Tooltip
Renders tooltip at given element on mouse over or other event
Source
LLM docs
Docs
Package
Usage
Tooltip children
Tooltip requires an element or a component as a single child – strings, fragments, numbers and multiple elements/components are not supported and will throw an error. Custom components must provide a prop to get the root element ref; all Mantine components support ref out of the box.
Tooltip target
The target prop is an alternative to children. It accepts a string (selector),
an HTML element or a ref object with an HTML element. Use the target prop when you do
not render the tooltip target as a JSX element.
Example of using the target prop with a string selector:
Required ref prop
Custom components that are rendered inside Tooltip are required to support ref prop:
The component must support ref prop:
Color
Offset
Set the offset prop to a number to change the tooltip position relative to the target element.
This way you can control the tooltip offset on the main axis only.
To control the offset on both axes, pass an object with mainAxis and crossAxis properties:
Arrow
Set the withArrow prop to add an arrow to the tooltip. The arrow is a div element rotated with transform: rotate(45deg).
The arrowPosition prop determines how the arrow is positioned relative to the target element when position is set to *-start and *-end values on the Popover component.
By default, the value is center – the arrow is positioned in the center of the target element if it is possible.
If you change arrowPosition to side, then the arrow will be positioned on the side of the target element,
and you will be able to control the arrow offset with the arrowOffset prop. Note that when arrowPosition is set to center,
the arrowOffset prop is ignored.
If you set arrowPosition to merge, the arrow will form a right triangle merged with the corresponding
corner of the tooltip, and the border radius of that corner will be removed. This mode only works
with *-start and *-end positions. Note that arrowOffset and arrowRadius props are ignored
when arrowPosition is set to merge.
Controlled
Change events
Events that trigger the tooltip can be changed with the events prop; it accepts an object
with the following properties that determine which events will trigger the tooltip:
hover– mouse hover event,trueby defaultfocus– focus/blur events excluding clicks on the target element,falseby defaulttouch– events for touchscreen devices,falseby default
Interactive tooltip
By default, the tooltip closes as soon as the pointer leaves the target element, and the tooltip body ignores pointer events. Set the interactive prop to keep the tooltip open while the pointer travels from the target to the tooltip and rests over its content:
Set interactive if the tooltip contains content that the user must be able to reach with a pointer, for example a link. It is also required by WCAG 2.1 success criterion 1.4.13: Content on Hover or Focus, which states that content that appears on hover must remain visible while the pointer is over it.
Note that an interactive tooltip receives pointer events, which means that while it is open, it intercepts clicks and hover events of the elements that it overlaps. The tooltip stops receiving pointer events as soon as it starts closing. The interactive prop is not supported by Tooltip.Floating, which always follows the mouse.
Multiline
To enable multiline mode, set the multiline prop to enable line breaks and the w style prop to set the tooltip width:
Inline
Set the inline prop to use Tooltip with inline elements:
Stantler’s magnificent antlers were traded at high prices as works of art. As a result, this Pokémon was hunted close to extinction by those who were after the priceless antlers. When visiting a junkyard, you may catch sight of it having an intense fight with Murkrow over shiny objects.Ho-Oh’s feathers glow in seven colors depending on the angle at which they are struck by light. These feathers are said to bring happiness to the bearers. This Pokémon is said to live at the foot of a rainbow.
Change transition
Tooltip is built with the Transition component; it supports transitionProps props:
All available premade transitions:
Close and open delay
You can delay tooltip open/close events by setting the openDelay and closeDelay props in ms:
Tooltip delay group
The Tooltip.Group component can be used to sync open and close delays for multiple tooltips:
Floating tooltip
Tooltip.Floating component has the same API as the Tooltip component but the tooltip will follow the mouse:
Accessibility
Tooltip follows the WAI-ARIA tooltip pattern:
- The tooltip body has
role="tooltip"attribute - The target element has
aria-describedbyattribute Tooltip.Floatingis ignored by screen readers- Uncontrolled tooltips are dismissed with
Escapewithout moving the pointer or focus
By default, Tooltip is not triggered by focus events and thus users who use a screen reader
or navigate with the keyboard will not be able to get tooltip content. Set the events prop to enable
focus/blur tooltip events:
WCAG 2.1 success criterion 1.4.13: Content on Hover or Focus
additionally requires content that appears on hover to be dismissable, hoverable and persistent.
Tooltip is persistent out of the box and dismissable if its opened state is not controlled
(Escape closes it without moving the pointer – if you control the opened prop, you are responsible
for handling Escape yourself). Tooltip is not hoverable by default – set the
interactive prop to make the tooltip body hoverable: