A tooltip displays a description of an element on hover or focus.
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
TooltipTrigger 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/Tooltip';
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. | ||
isOpen | boolean | Default: — |
Whether the overlay is open by default (controlled). | ||
defaultOpen | boolean | Default: — |
Whether the overlay is open by default (uncontrolled). | ||
onOpenChange | | Default: — |
Handler that is called when the overlay's open state changes. | ||
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. | ||
isOpen | boolean | Default: — |
Whether the element is rendered. | ||
defaultOpen | boolean | Default: — |
Whether the overlay is open by default (uncontrolled). | ||
onOpenChange | | Default: — |
Handler that is called when the overlay's open state changes. | ||
shouldFlip | boolean | Default: true
|
Whether the element should flip its orientation (e.g. top to bottom or left to right) when there is insufficient room for it to render completely. | ||
offset | number | Default: 0
|
The additional offset applied along the main axis between the element and its anchor element. | ||
crossOffset | number | Default: 0
|
The additional offset applied along the cross axis between the element and its anchor element. | ||
containerPadding | number | Default: 12
|
The placement padding that should be applied between the element and its surrounding container. | ||
style | StyleOrFunction | Default: — |
The inline style for the element. A function may be provided to compute the style based on component state. | ||
className | ClassNameOrFunction | Default: 'react-aria-Tooltip'
|
The CSS className for the element. A function may be provided to compute the class based on component state. | ||
aria-label | string | Default: — |
Defines a string value that labels the current element. | ||
aria-labelledby | string | Default: — |
Identifies the element (or elements) that labels the current element. | ||
aria-describedby | string | Default: — |
Identifies the element (or elements) that describes the object. | ||
aria-details | string | Default: — |
Identifies the element (or elements) that provide a detailed, extended description for the object. | ||
render | DOMRenderFunction | Default: — |
Overrides the default DOM element with a custom render function. This allows rendering existing components with built-in styles and behaviors such as router links, animation libraries, and pre-styled components. Requirements:
| ||
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. | ||
style | StyleOrFunction | |
The inline style for the element. A function may be provided to compute the style based on component state. | ||
className | ClassNameOrFunction | |
The CSS className for the element. A function may be provided to compute the class based on component state. | ||
id | string | |
The element's unique identifier. See MDN. | ||
render | DOMRenderFunction | |
Overrides the default DOM element with a custom render function. This allows rendering existing components with built-in styles and behaviors such as router links, animation libraries, and pre-styled components. Requirements:
| ||
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. | |