Tooltip
Renders tooltip at given element on mouse over or other event
Import
Source
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 error. Custom components must provide a prop to get root element ref, all Mantine components support ref out of the box.
Required ref prop
Custom components that are rendered inside Tooltip
are required to support ref
prop:
Use forwardRef
function to forward ref to root element:
Color
Offset
Set offset
prop to a number to change tooltip position relative to the target element.
This way you can control tooltip offset on main axis only.
To control offset on both axis, pass object with mainAxis
and crossAxis
properties:
Arrow
Set withArrow
prop to add an arrow to the tooltip. Arrow is a div
element rotated with transform: rotate(45deg)
.
arrowPosition
prop determines how arrow is position relative to the target element when position
is set to *-start
and *-end
values on 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 arrow offset with arrowOffset
prop. Note that when arrowPosition
is set to center
,
arrowOffset
prop is ignored.
Controlled
Change events
Events that trigger tooltip can be changed with events
prop, it accepts an object
with the following properties that determine which events will trigger tooltip:
hover
– mouse hover event,true
by defaultfocus
– focus/blur events excluding clicks on the target element,false
by defaulttouch
– events for touchscreen devices,false
by default
Multiline
To enable multiline mode, set multiline
prop to enable line breaks and w
style prop to set tooltip width:
Inline
Set 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 Transition component, it supports transitionProps
props:
All available premade transitions:
Close and open delay
You can delay tooltip open/close events by setting openDelay
and closeDelay
props in ms:
Tooltip delay group
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 Tooltip component but tooltip will follow mouse:
Custom components with Tooltip
If you want to build a component that can be used with Tooltip use forwardRef or other prop that will allow to get root element ref. This logic is applied to Tooltip and Tooltip.Floating components:
Accessibility
Tooltip follows WAI-ARIA recommendations:
- Tooltip body has
role="tooltip"
attribute - Target element has
aria-describedby
attribute Tooltip.Floating
is ignored by screen readers
By default, Tooltip is not triggered by focus events and thus users who use a screen reader
or navigate with keyboard will not be able to get tooltip content. Set events
prop to enable
focus/blur tooltip events: