Tooltip
A short floating label explaining an element. Nothing in it can be clicked, so never put an action there.
not-compliant
- Overview
- Props
- Figma
Usage
Placement
Inline
By default, tooltip triggers are rendered as flex elements. If they are inside a Text element, they will be inline instead.
It's also possible to control this behavior through the inline prop.
Stantler’s magnificent antlers were traded at high prices as works of art. As a result, this Pokémon was hunted close to extinction by those who were after the priceless antlers.
Controlled
If you need to control the tooltip visibility (instead of it being controlled by hover/focus), you can use the open prop.
Custom label
While tooltips should only be used for short text (a few words), it is sometimes useful to customize what they render. When doing so, hust use <Text /> component to render text inside that custom label and get expected styling:
Accessibility
Adheres to the WAI-ARIA Tooltip Pattern.
Playground
Tooltip props
| Name | Type | Default Value | Description | Usage count |
|---|---|---|---|---|
| asChild | booleanundefined | false | Instead of wrapping the child, apply styles and accessibility attributes to it | |
| children* | ReactNode | Target element that will trigger the tooltip on hover when uncontrolled | ||
| inline | booleanundefined | Set if tooltip is attached to an inline element. Defaults to `true` when inside a Text element | ||
| label* | 3 possibilitiesstringReactElement<unknown, stringJSXElementConstructor<any>> | Tooltip label. When passing something more complex than a string, React components can be used | ||
| onOpenChange | ((open: boolean) => void)undefined | Called when tooltip is opened or closed | ||
| open | booleanundefined | When controlled, decide if tooltip should be visible or not | ||
| placement | Placementundefined | Tooltip placement relative to target element |