Tooltip

A tooltip on web, with only accessibility output on native

import {
ChevronDown,
ChevronLeft,
ChevronRight,
ChevronUp,
Circle,
} from '@tamagui/lucide-icons'
import type { TooltipProps } from 'tamagui'
import { Button, Paragraph, Tooltip, TooltipGroup, XStack, YStack } from 'tamagui'
export function TooltipDemo() {
return (
<TooltipGroup delay={{ open: 3000, close: 100 }}>
<YStack space="$2" alignSelf="center">
<XStack space="$2">
<Demo groupId="0" placement="top-end" Icon={Circle} />
<Demo groupId="1" placement="top" Icon={ChevronUp} />
<Demo groupId="2" placement="top-start" Icon={Circle} />
</XStack>
<XStack space="$2">
<Demo groupId="3" placement="left" Icon={ChevronLeft} />
<YStack flex={1} />
<Demo groupId="4" placement="right" Icon={ChevronRight} />
</XStack>
<XStack space="$2">
<Demo groupId="5" placement="bottom-end" Icon={Circle} />
<Demo groupId="6" placement="bottom" Icon={ChevronDown} />
<Demo groupId="7" placement="bottom-start" Icon={Circle} />
</XStack>
</YStack>
</TooltipGroup>
)
}
function Demo({ Icon, ...props }: TooltipProps & { Icon?: any }) {
return (
<Tooltip {...props}>
<Tooltip.Trigger>
<Button icon={Icon} circular />
</Tooltip.Trigger>
<Tooltip.Content enterStyle={{ x: 0, y: -5, opacity: 0, scale: 0.9 }} exitStyle={{ x: 0, y: -5, opacity: 0, scale: 0.9 }} scale={1} x={0} y={0} opacity={1} animation={[ 'quick', { opacity: { overshootClamping: true, }, }, ]} >
<Tooltip.Arrow />
<Paragraph size="$2" lineHeight="$1">
Hello world
</Paragraph>
</Tooltip.Content>
</Tooltip>
)
}

Features

  • Doesn't open until your mouse stops moving.

  • Easy to animate enter and exit.

  • Sizable, positionable, unstyled or styled.

Note that Tooltip doesn't render on native platforms.

Installation

Tooltip is already installed in tamagui, or you can install it independently:

yarn @tamagui/tooltip

PortalProvider

When rendering into root of app instead of inline, you'll first need to install the @tamagui/portal package:

yarn @tamagui/portal

Then add PortalProvider to the root of your app:

App.tsx

import { PortalProvider } from '@tamagui/portal'
import YourApp from './components/YourApp'
function App() {
return (
<PortalProvider shouldAddRootHost>
<YourApp />
</PortalProvider>
)
}
export default App

Props

  • shouldAddRootHost

    boolean

    Defines whether to add a default root host or not.

  • Anatomy

    import { Tooltip } from 'tamagui' // or '@tamagui/tooltip'
    export default () => (
    <Tooltip>
    <Tooltip.Trigger />
    <Tooltip.Content>
    <Tooltip.Arrow />
    {/* ... */}
    </Tooltip.Content>
    </Tooltip>
    )

    API Reference

    Tooltip

    Contains every component for the tooltip.

    Props

  • children (required)

    React.ReactNode

    Must contain Popover.Content

  • groupId

    string

    If given, will work alongside TooltipGroup to ensure only one tooltip in the groups stays open.

  • restMs

    number

    Time needed for cursor to rest before showing.

  • delay

    number | { open?: number; close?: number }

    Maximum time before showing (can be set independently for open/close).

  • size

    SizeTokens

    Passes size down too all sub-components when set for padding, arrow, borderRadius

  • placement

    Placement

    'top' | 'right' | 'bottom' | 'left' | 'top-start' | 'top-end' | 'right-start' | 'right-end' | 'bottom-start' | 'bottom-end' | 'left-start' | 'left-end'

  • open

    boolean

  • defaultOpen

    boolean

  • onOpenChange

    (open: boolean) => void

  • modal

    boolean

    Default: 

    true

    Renders into root of app instead of inline

  • stayInFrame

    ShiftProps

    See floating-ui shift()

  • allowFlip

    FlipProps

    See floating-ui flip

  • offset

    OffsetOptions

    Determines the distance the Popover appears from the target, see floating-ui offset().

  • If using modal={true} (which is true by default), refer to the PortalProvider installation for more information.

    Tooltip.Trigger

    Used to trigger opening of the popover when uncontrolled, see YStack in Stacks.

    Tooltip.Content

    Renders as SizableStack (see Stacks) with an extra size prop that accepts any SizeTokens.

    Tooltip.Anchor

    Renders as YStack, see Stacks.

    When you want the Trigger to be in another location from where the Tooltip attaches, use Anchor. When used, Anchor is where the Tooltip will attach, while Trigger will open it.

    Previous

    Sheet

    Next

    Toast