A floating label to explain additional context in the UI. They're triggered by interaction events like hover, focus, tap, or click.
The component can be imported via:
We use Floating UI as the main library for positioning the tooltips, and attaching the interactions.
At its most simple, a tooltip can be invoked like this:
The tooltip "trigger" will render as an unstyled button tag, to make it
focusable and visible to assistive technology.
When the tooltip is attached to text, the isUnderlined prop can be used to add
a bottom border to it, to draw attention:
The component accepts a placement argument, which accepts one of these values:
By default, the tooltip will show/hide after a 250ms delay after receiving
focus/hovering. This can be changed with the floatingPluginOptions prop,
by customizing the hover settings:
Additionally, an object can be provided with separate open and close delays,
when we'd like to control the delays before opening/closing more precisely:
The PlumaTooltipGroup component can be used to group multiple components together,
and have them sync their open/close delays. Once one tooltip in a group is open,
hovering over another tooltip trigger in the same group will open it immediately,
instead of having to wait for another open delay.
Only one tooltip in a group can be open at a time.
As mentioned above, the tooltip trigger will render as a button, which may
sometimes cause the layout to break. In case more customization is needed,
the component accepts an isCustom prop, which will prevent it from rendering
any containing elements.
When using custom tooltips, the rendered content receives a function, which contains Floating UI props/styles. You will need to forward/spread those props to your custom trigger element in order for all interactions to connect:
A tooltip's content is meant to be text-only, and it shouldn't contain any interactive elements, like links.
While not recommended, it's possible to customize the content of the tooltip as
well, by not providing a content prop, and instead using the TooltipContent
component. This works for both isCustom and standard tooltips.
Note: it is not necessary to call setFloating or spread any props on the
content component - it does so automatically by getting its props and refs from
context.
The isDisabled prop can be used to conditionally enable/disable a tooltip. When
isDisabled is true, the tooltip will not show up on hover/focus.
In addition to the existing middlewareOptions prop for customizing the behavior of the tooltip,
it's possible to provide entire custom middleware functions, which can be used for more complex scenarios or special use cases.
For example, we can create a middleware that changes the position of the tooltip's arrow:
Additional middleware to apply to Floating UI, for example custom middleware for more control. These will be applied after the default middleware.
Default:125
The duration (in ms) for the tooltip's show/hide animation.
The text content to show in the tooltip
Default:false
Whether the tooltip should be open on first render
Additional options to pass into Floating UI's effects (useHover, useFocus, useDismiss, useRole).
For example, delay in hover can control the delay before the tooltip appears.
Whether the tooltip will be applied to a custom element
Default:false
Whether the tooltip should be disabled. Can be used to conditionally enable/disable a tooltip depending on state.
Default:true
Whether to apply a flex style to the trigger (by default it's inline-flex)
Whether the tooltip should be open. Only use this along with onOpenChange if you want to control the state of the tooltip
Whether the trigger element should show a bottom border for emphasis
Called when the open state of the tooltip is changing
Default:bottom
Where the tooltip should be placed in relation to the trigger
Default:absolute
The position CSS property to use on the floating element
Additional classes to apply on the tooltip component (the floating element, not the trigger). Should only be used as a last resort
Additional inline styles to apply on the tooltip component (the floating element, not the trigger). Should only be used as a last resort
Default:true
Whether the tooltip content should show an arrow.