The react component to use as the trigger for the tooltip
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
Tooltipis wrapping a functional component, ensure that the functional component accepts arefusingforwardRef.
With an icon#
Note 🚨: If you're wrapping an icon from
react-icons, you need to also wrap the icon in aspanelement asreact-iconsicons 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#
childrenrequired
childrenrequiredReactNodearia-label
aria-labelThe 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
stringarrowPadding
arrowPaddingThe padding required to prevent the arrow from reaching the very edge of the popper.
number8arrowShadowColor
arrowShadowColorstringarrowSize
arrowSizenumbercloseDelay
closeDelayDelay (in ms) before hiding the tooltip
number0mscloseOnClick
closeOnClickIf true, the tooltip will hide on click
booleancloseOnMouseDown
closeOnMouseDownIf true, the tooltip will hide while the mouse
is down
booleancolorScheme
colorSchemeColor Schemes for Tooltip are not implemented in the default theme. You can extend the theme to implement them.
"whiteAlpha" | "blackAlpha" | "gray" | "red" | "orange" | "yellow" | "green" | "teal" | "blue" | "cyan" | "purple" | "pink" | "linkedin" | "facebook" | "messenger" | "whatsapp" | "twitter" | "telegram"defaultIsOpen
defaultIsOpenIf true, the tooltip will be initially shown
booleangutter
gutterThe distance or margin between the reference and popper.
It is used internally to create an offset modifier.
NB: If you define offset prop, it'll override the gutter.
number8hasArrow
hasArrowIf true, the tooltip will show an arrow tip
booleanisDisabled
isDisabledbooleanisOpen
isOpenIf true, the tooltip will be shown (in controlled mode)
booleanlabel
labelThe label of the tooltip
ReactNodemodifiers
modifiersArray of popper.js modifiers. Check the docs to see the list of possible modifiers you can pass. @see Docs https://popper.js.org/docs/v2/modifiers/
Partial<Modifier<string, any>>[]offset
offsetThe main and cross-axis offset to displace popper element from its reference element.
[crossAxis: number, mainAxis: number]onClose
onCloseCallback to run when the tooltip hides
(() => void)onOpen
onOpenCallback to run when the tooltip shows
(() => void)openDelay
openDelayDelay (in ms) before showing the tooltip
number0msplacement
placementThe Popper.js placement of the tooltip
"bottom" | "left" | "right" | "top" | "auto" | "auto-start" | "auto-end" | "top-start" | "top-end" | "bottom-start" | "bottom-end" | "right-start" | "right-end" | "left-start" | "left-end"portalProps
portalPropsProps to be forwarded to the portal component
Pick<PortalProps, "appendToParentPortal" | "containerRef">shouldWrapChildren
shouldWrapChildrenIf true, the tooltip will wrap its children
in a `<span/>` with `tabIndex=0`
booleansize
sizeSizes for Tooltip are not implemented in the default theme. You can extend the theme to implement them.
stringvariant
variantVariants for Tooltip are not implemented in the default theme. You can extend the theme to implement them.
string