A tooltip is a brief, informative message that appears when a user interacts with an element. Tooltips are usually initiated in one of two ways: through a mouse-hover gesture or through a keyboard-hover gesture.
The Tooltip component follows the WAI-ARIA Tooltip Pattern.
If the children
of Tooltip is a string
, we wrap with in a span
with
tabIndex
set to 0
, to ensure it meets the accessibility requirements.
Note 🚨: If the Tooltip is wrapped in a functional component. Ensure you
forwardRef
to this component.
If the children of the tooltip is a focusable element, the tooltip will show when you focus or hover on the element, and will hide when you blur or move cursor out of the element.
If the children of the tooltip is a focusable element, the tooltip will show when you focus or hover on the element, and will hide when you blur or move cursor out of the element.
Using the placement
prop you can adjust where your tooltip will be displayed.
Name | Type | Default | Description |
---|---|---|---|
label | string | The label of the tooltip. | |
aria-label | string | An alternate label for screen readers. | |
placement | PopperJS.Placement | bottom | Position the tooltip relative to the trigger element as well as surrounding elements. |
hasArrow | boolean | If true display an arrow tip on the tooltip. | |
children | React.ReactNode | The ReactNode to be used as the trigger of the tooltip. | |
shouldWrapChildren | boolean | If true , the tooltip will wrap the children in a span with tabIndex=0 | |
isOpen | boolean | If true , the tooltip is shown. | |
defaultIsOpen | boolean | If true , the tooltip is initially shown. | |
openDelay | number | 0 | The delay in ms for the tooltip to show |
closeDelay | number | 0 | The delay in ms for the tooltip to hide |
closeOnClick | boolean | true | If true hide the tooltip, when the trigger is clicked. |
onOpen | function | Function called when the tooltip shows. | |
onClose | function | Function called when the tooltip hides. | |
isDisabled | boolean | false | If true , the tooltip is not shown onHover, mouseOver, or other triggers. |
closeOnMouseDown | boolean | true | If true , the tooltip will close on mouse down |