Tooltip
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.
Import#
import { Tooltip } from "@chakra-ui/react"
Usage#
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 wrapping a functional component, ensure that the functional component accepts aref
usingforwardRef
.
With an icon#
Note 🚨: If you're wrapping an icon from
react-icons
, you need to also wrap the icon in aspan
element asreact-icons
icons do not useforwardRef
.
With arrow#
Tooltip with focusable content#
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.
Disabled Tooltip#
Placement#
Using the placement
prop you can adjust where your tooltip will be displayed.
More examples#
Props#
Name | Type | Description | Default |
---|---|---|---|
children | requiredReactNode | The react component to use as the trigger for the tooltip | - |
aria-label | string | The accessible, human friendly label to use for screen readers. If passed, tooltip will show the content `label` but expose only `aria-label` to assistive technologies | - |
arrowPadding | number | The distance of the arrow to its next border (numeric) E.g. arrowPadding = borderRadius * 2 | - |
arrowShadowColor | string | - | |
arrowSize | number | - | |
closeDelay | number | Delay (in ms) before hiding the tooltip | 0ms |
closeOnClick | boolean | If `true`, the tooltip will hide on click | - |
closeOnMouseDown | boolean | If `true`, the tooltip will hide while the mouse is down | - |
colorScheme | "blue" | "cyan" | "gray" | "green" | "orange" | "pink" | "purple" | "red" | "teal" | "yellow" | "whiteAlpha" | "blackAlpha" | "linkedin" | "facebook" | "messenger" | "whatsapp" | "twitter" | "telegram" | Color Schemes for Tooltip are not implemented in the default theme. You can extend the theme to implement them. | - |
defaultIsOpen | boolean | If `true`, the tooltip will be initially shown | - |
gutter | number | - | |
hasArrow | boolean | If `true`, the tooltip will show an arrow tip | - |
isDisabled | boolean | - | |
isOpen | boolean | If `true`, the tooltip will be shown (in controlled mode) | - |
label | ReactNode | The label of the tooltip | - |
modifiers | Modifier<string, any>[] | - | |
offset | [number, number] | - | |
onClose | (() => void) | Callback to run when the tooltip hides | - |
onOpen | (() => void) | Callback to run when the tooltip shows | - |
openDelay | number | Delay (in ms) before showing the tooltip | 0ms |
placement | "top" | "right" | "bottom" | "left" | "auto" | "auto-start" | "auto-end" | "top-start" | "top-end" | "bottom-start" | "bottom-end" | "right-start" | "right-end" | "left-start" | "left-end" | The Popper.js placement of the tooltip | - |
portalProps | Pick<PortalProps, "appendToParentPortal" | "containerRef"> | Props to be forwarded to the portal component | - |
shouldWrapChildren | boolean | If `true`, the tooltip will wrap its children in a `<span/>` with `tabIndex=0` | - |
size | string | Sizes for Tooltip are not implemented in the default theme. You can extend the theme to implement them. | - |
variant | string | Variants for Tooltip are not implemented in the default theme. You can extend the theme to implement them. | - |