Tooltip
A popup that displays information related to an element when the element is hovered or receives keyboard focus.
Preview
Installation
npx sigma-ui@latest add tooltipUsage
<script setup lang="ts">
import { Button } from '@/components/ui/button';
import {
Tooltip,
TooltipContent,
TooltipProvider,
TooltipTrigger,
} from '@/components/ui/tooltip';
</script>
<template>
<TooltipProvider>
<Tooltip>
<TooltipTrigger as-child>
<Button variant="outline">
Hover
</Button>
</TooltipTrigger>
<TooltipContent>
<p>Add to library</p>
</TooltipContent>
</Tooltip>
</TooltipProvider>
</template>TooltipProvidershares the open delay between tooltips. Wrap your app, or a section of it, once.- Use
delayDurationonTooltiporTooltipProviderto change how long the pointer must rest before the tooltip opens. - Use
as-childonTooltipTriggerto make your own focusable element the trigger.
Examples
No Delay
Set delayDuration to 0 to open the tooltip as soon as the trigger is hovered.
<template>
<TooltipProvider>
<Tooltip :delay-duration="0">
<TooltipTrigger as-child>
<Button variant="outline">
Hover
</Button>
</TooltipTrigger>
<TooltipContent side="right">
<p>Add to library</p>
</TooltipContent>
</Tooltip>
</TooltipProvider>
</template>API Reference
Tooltip
Props
| Prop | Type | Default |
|---|---|---|
defaultOpenThe open state of the tooltip when it is initially rendered. Use when you do not need to control its open state. | boolean | - |
openThe controlled open state of the tooltip. | boolean | - |
delayDurationOverride the duration given to the | number | 700 |
disableHoverableContentPrevents Tooltip.Content from remaining open when hovering. Disabling this has accessibility consequences. Inherits from Tooltip.Provider. | boolean | - |
disableClosingTriggerWhen | boolean | false |
disabledWhen | boolean | false |
ignoreNonKeyboardFocusPrevent the tooltip from opening if the focus did not come from
the keyboard by matching against the | boolean | false |
Events
| Event | Payload |
|---|---|
update:openEvent handler called when the open state of the tooltip changes. | [value: boolean] |
Slots
| Slot | Scope |
|---|---|
defaultThe content of the component. | - |
TooltipContent
Props
| Prop | Type | Default |
|---|---|---|
forceMountUsed to force mounting when more control is needed. Useful when controlling animation with Vue animation libraries. | boolean | - |
ariaLabelBy default, screenreaders will announce the content inside the component. If this is not descriptive enough, or you have content that cannot be announced, use aria-label as a more descriptive label. | string | String |
asChildChange the default rendered element for the one passed as a child, merging their props and behavior. Read our Composition guide for more details. | boolean | - |
asThe element or component this component should render as. Can be overwritten by | AsTag | Component | "div" |
sideThe preferred side of the trigger to render against when open. Will be reversed when collisions occur and avoidCollisions is enabled. | "top" | "right" | "bottom" | "left" | "bottom" |
sideOffsetThe distance in pixels from the trigger. | number | 4 |
alignThe preferred alignment against the trigger. May change when collisions occur. | "center" | "start" | "end" | "center" |
alignOffsetAn offset in pixels from the | number | 0 |
avoidCollisionsWhen | boolean | true |
collisionBoundaryThe element used as the collision boundary. By default this is the viewport, though you can provide additional element(s) to be included in this check. | Element | (Element | null)[] | null | [] |
collisionPaddingThe distance in pixels from the boundary edges where collision detection should occur. Accepts a number (same for all sides), or a partial padding object, for example: { top: 20, left: 20 }. | number | Partial<Record<"top" | "right" | "bottom" | "left", number>> | 0 |
arrowPaddingThe padding between the arrow and the edges of the content. If your content has border-radius, this will prevent it from overflowing the corners. | number | 0 |
stickyThe sticky behavior on the align axis. | "partial" | "always" | "partial" |
hideWhenDetachedWhether to hide the content when the trigger becomes fully occluded. | boolean | false |
positionStrategyThe type of CSS position property to use. | "absolute" | "fixed" | - |
updatePositionStrategyStrategy to update the position of the floating element on every animation frame. | "always" | "optimized" | 'optimized' |
Events
| Event | Payload |
|---|---|
escapeKeyDownEvent handler called when focus moves to the destructive action after opening. It can be prevented by calling | [event: KeyboardEvent] |
pointerDownOutsideEvent handler called when a pointer event occurs outside the bounds of the component. It can be prevented by calling | [event: Event] |
Slots
| Slot | Scope |
|---|---|
defaultThe content of the component. | - |
TooltipTrigger
Props
| Prop | Type | Default |
|---|---|---|
referenceThe reference (or anchor) element that is being referred to for positioning. If not provided will use the current component as anchor. | ReferenceElement | - |
asChildChange the default rendered element for the one passed as a child, merging their props and behavior. Read our Composition guide for more details. | boolean | - |
asThe element or component this component should render as. Can be overwritten by | AsTag | Component | "div" |
Slots
| Slot | Scope |
|---|---|
defaultThe content of the component. | - |
TooltipProvider
Props
| Prop | Type | Default |
|---|---|---|
delayDurationThe duration from when the pointer enters the trigger until the tooltip gets opened. | number | 700 |
skipDelayDurationHow much time a user has to enter another trigger without incurring a delay again. | number | 300 |
disableHoverableContentWhen | boolean | false |
disableClosingTriggerWhen | boolean | false |
disabledWhen | boolean | false |
ignoreNonKeyboardFocusPrevent the tooltip from opening if the focus did not come from
the keyboard by matching against the | boolean | false |
contentDefault settings that will be used by all tooltip components. | TooltipContentProps | - |
Slots
| Slot | Scope |
|---|---|
defaultThe content of the component. | - |
Accessibility
Adheres to the Tooltip WAI-ARIA design pattern. Reka UI opens the tooltip on hover and keyboard focus, and links it to the trigger with aria-describedby.
| Key | Description |
|---|---|
| Tab | Opens or closes the tooltip without delay. |
| Space | If open, closes the tooltip without delay. |
| Enter | If open, closes the tooltip without delay. |
| Escape | If open, closes the tooltip without delay. |