Tooltip

A short label that appears when the user points at or focuses an element.

Shortcut and parts

Tooltip covers the common case: pass the tip as content and wrap the trigger. For full control, such as a custom layout, compose Tooltip.Root, Tooltip.Trigger, Tooltip.Positioner, and Tooltip.Content yourself. With Parts builds the same tooltip both ways.

Usage

Code
import { Tooltip } from '@leverui/components';
Code
<Tooltip content="...">{(getProps) => <button {...getProps()} />}</Tooltip>

Examples

Arrow

Use the showArrow prop to show an arrow on the tooltip.

Placement

Use the positioning.placement prop to change the position of the tooltip.

Offset

Use the positioning.offset prop to change the offset of the tooltip.

Delay

Use the openDelay and closeDelay prop to change the delay of the tooltip.

Custom Background

Use the --leverui-tooltip-background CSS variable to change the background color of the tooltip.

Controlled

Use the open and onOpenChange prop to control the visibility of the tooltip.

Store

An alternative way to control the tooltip is to use the RootProvider component and the useTooltip store hook.

This way you can access the tooltip state and methods from outside the tooltip.

Interactive

Use the interactive prop to keep the tooltip open when interacting with its content.

Disabled

Use the disabled prop to disable the tooltip. When disabled, the tooltip will not be shown.

With Avatar

Here's an example of how to use the Tooltip component with an Avatar component.

ME

With Checkbox

Here's an example of how to use the Tooltip component with a Checkbox component.

With MenuItem

Here's an example of how to use the Tooltip with a MenuItem component.

With MenuTrigger

Here's an example of how to use the Tooltip with a MenuTrigger component.

With Switch

Here's an example of how to wrap Tooltip around a Switch component.

With Tabs

Here's an example of how to wrap Tooltip around a Tabs component.

Invite people and set their roles.

With Parts

Both buttons show the same tooltip. The first uses the Tooltip shortcut; the second composes Tooltip.Root, Tooltip.Trigger, Tooltip.Positioner, and Tooltip.Content for full control.

Guides

Trigger

The Tooltip shortcut takes its trigger as a Solid render function. Spread getProps() on your element to keep the hover and focus behavior and the accessible link to the tooltip.

Accessibility

Give the trigger a clear name of its own. The tooltip only adds to it. Keep essential instructions visible outside the tooltip. For content with links or controls people need to use, choose Popover or HoverCard.

Props

Root

PropDefaultTypeDescription
closeDelay150numberWait before closing, in milliseconds.
closeOnClicktruebooleanClose on click.
closeOnEscapetruebooleanClose on Escape.
closeOnPointerDowntruebooleanClose on pointer down.
closeOnScrolltruebooleanClose on scroll.
lazyMounttruebooleanRender the content only once the tooltip first opens.
openDelay400numberWait before opening, in milliseconds.
unmountOnExittruebooleanRemove the content from the DOM on close.
unstyled—booleanTurn off the default styles.
aria-label—stringCustom label for the tooltip.
defaultOpen—booleanOpen at first. Uncontrolled.
defaultTriggerValue—stringTrigger value at first. Uncontrolled.
disabled—booleanDisable the tooltip.
id—stringUnique id.
ids—Element ID mapIds of the tooltip's elements. For combining with other components.
immediate—booleanApply a present change right away, not on the next frame.
interactivefalsebooleanLet the user interact with the content. Stays open while the pointer is over it.
onExitComplete—VoidFunctionCalled when the closing animation ends.
onOpenChange—(details: OpenChangeDetails) => voidCalled when the tooltip opens or closes.
onTriggerValueChange—(details: TriggerValueChangeDetails) => voidCalled when the trigger value changes.
open—booleanOpen state. Controlled.
positioning—PositioningOptionsPlacement options for the content.
present—booleanPresent state. Controlled.
skipAnimationOnMountfalsebooleanSkip the animation on first render.
triggerValue—stringTrigger value. Controlled.

The Tooltip shortcut also takes content, contentProps, showArrow, portalled, and portalRef.

Customize with CSS

For one-off changes, set class or style on a part, or override its public CSS variables.

Code
.account-tooltip {
  --leverui-tooltip-background: #20304a;
  --leverui-tooltip-foreground: white;
}

Add class="account-tooltip" to Tooltip.Content. The arrow takes its background from the content. unstyled on Tooltip.Root or a part turns off the default styles. Behavior stays the same.

Explorer

Click a part name in the sidebar to highlight it in the preview.

Component Anatomy

Hover to highlight, click to select parts