A tooltip displays a description of an element on hover or focus.
Vanilla CSS theme
--tint CSS variable used by the Vanilla CSS examples.Interactions
Tooltips appear after a "warmup" delay when hovering, or instantly on focus. Once a tooltip is displayed, other tooltips display immediately. If the user waits for the "cooldown period" before hovering another element, the warmup timer restarts.
Accessibility
Custom trigger
DialogTrigger works with any focusable React Aria component (e.g. Button, Link, etc.). Use the <Focusable> component to wrap a custom trigger element such as a third party component or DOM element.
import {Focusable, TooltipTrigger} from 'react-aria-components';
import {Tooltip} from './Tooltip';
<TooltipTrigger>
<Focusable>
<span role="button">Custom trigger</span>
</Focusable>
<Tooltip>Tooltip</Tooltip>
</TooltipTrigger>
Accessibility
<Focusable> child must have an ARIA role or use an appropriate semantic HTML element so that screen readers can announce the tooltip. Trigger components must forward their ref and spread all props to a DOM element.const CustomTrigger = React.forwardRef((props, ref) => (
<button {...props} ref={ref} />
));
DialogTrigger or MenuTrigger with a <Pressable> trigger also works with TooltipTrigger. All <Pressable> elements are already focusable, so there's no need to wrap them in <Focusable>.
API
<TooltipTrigger>
<Button />
<Tooltip>
<OverlayArrow />
</Tooltip>
</TooltipTrigger>
TooltipTrigger
TooltipTrigger wraps around a trigger element and a Tooltip. It handles opening and closing the Tooltip when the user hovers over or focuses the trigger, and positioning the Tooltip relative to the trigger.
| Name | Type | Default |
|---|---|---|
children | ReactNode | Default: — |
isDisabled | boolean | Default: — |
| Whether the tooltip should be disabled, independent from the trigger. | ||
delay | number | Default: 1500
|
| The delay time for the tooltip to show up. See guidelines. | ||
closeDelay | number | Default: 500
|
| The delay time for the tooltip to close. See guidelines. | ||
trigger | 'hover' | 'focus' | Default: 'hover'
|
| By default, opens for both focus and hover. Can be made to open only for focus. | ||
shouldCloseOnPress | boolean | Default: true
|
| Whether the tooltip should close when the trigger is pressed. | ||
Tooltip
A tooltip displays a description of an element on hover or focus.
| Name | Type | Default |
|---|---|---|
triggerRef | RefObject | Default: — |
| The ref for the element which the tooltip positions itself with respect to. When used within a TooltipTrigger this is set automatically. It is only required when used standalone. | ||
isEntering | boolean | Default: — |
| Whether the tooltip is currently performing an entry animation. | ||
isExiting | boolean | Default: — |
| Whether the tooltip is currently performing an exit animation. | ||
placement | Placement | Default: 'top'
|
| The placement of the tooltip with respect to the trigger. | ||
arrowBoundaryOffset | number | Default: 0
|
| The minimum distance the arrow's edge should be from the edge of the overlay element. | ||
children | ChildrenOrFunction | Default: — |
| The children of the component. A function may be provided to alter the children based on component state. | ||
Default className: react-aria-Tooltip
| Render Prop | CSS Selector |
|---|---|
placement | CSS Selector: [data-placement="left | right | top | bottom"]
|
| The placement of the tooltip relative to the trigger. | |
isEntering | CSS Selector: [data-entering]
|
| Whether the tooltip is currently entering. Use this to apply animations. | |
isExiting | CSS Selector: [data-exiting]
|
| Whether the tooltip is currently exiting. Use this to apply animations. | |
state | CSS Selector: — |
| State of the tooltip. | |
| CSS Variable |
|---|
--trigger-anchor-point |
The position of the trigger relative to the tooltip. Use with transform-origin when applying scale transitions. |
OverlayArrow
An OverlayArrow renders a custom arrow element relative to an overlay element such as a popover or tooltip such that it aligns with a trigger element.
| Name | Type | |
|---|---|---|
children | ChildrenOrFunction | |
| The children of the component. A function may be provided to alter the children based on component state. | ||
Default className: react-aria-OverlayArrow
| Render Prop | CSS Selector |
|---|---|
placement | CSS Selector: [data-placement="left | right | top | bottom"]
|
| The placement of the overlay relative to the trigger. | |