Appearance
Tooltip
The Tooltip component displays contextual information on hover or focus. It is backed by Base UI's Tooltip primitive.
Import
tsx
import { Tooltip } from "@tailor-platform/app-shell";The examples below also import useState from react, Button and Text from @tailor-platform/app-shell, and PencilIcon from lucide-react.
Basic Usage
tsx
function BasicUsage() {
return (
<Tooltip.Root>
<Tooltip.Trigger render={<Button variant="outline" />}>Hover me</Tooltip.Trigger>
<Tooltip.Content>Helpful information</Tooltip.Content>
</Tooltip.Root>
);
}Sub-components
| Sub-component | Description |
|---|---|
Tooltip.Provider | Provides shared delay configuration for all nested tooltips |
Tooltip.Root | Manages tooltip open/close state |
Tooltip.Trigger | Element that shows the tooltip on hover or focus |
Tooltip.Content | The tooltip popup containing the help text |
Props
Tooltip.Provider Props
Wrap a section of your UI (e.g. a toolbar) with Tooltip.Provider to share delay settings across multiple tooltips.
| Prop | Type | Default | Description |
|---|---|---|---|
delay | number | 0 | Delay in ms before the tooltip opens (milliseconds) |
closeDelay | number | - | Delay in ms before the tooltip closes |
timeout | number | 400 | Window in ms during which the next tooltip opens immediately after the previous one closes |
children | React.ReactNode | - | Nested tooltip components |
Tooltip.Root Props
| Prop | Type | Default | Description |
|---|---|---|---|
open | boolean | - | Controlled open state |
defaultOpen | boolean | false | Initial open state (uncontrolled) |
onOpenChange | (open: boolean) => void | - | Callback when open state changes |
children | React.ReactNode | - | Tooltip sub-components |
Tooltip.Content Props
| Prop | Type | Default | Description |
|---|---|---|---|
side | "top" | "right" | "bottom" | "left" | "top" | Preferred placement of the tooltip |
align | "start" | "center" | "end" | "center" | Alignment along the placement axis |
sideOffset | number | 5 | Distance in px from the trigger |
noArrow | boolean | false | When true, suppresses the arrow indicator on the popup |
className | string | - | Additional CSS classes |
children | React.ReactNode | - | Tooltip text or content |
Placement
tsx
function Placement() {
return (
<Tooltip.Root>
<Tooltip.Trigger render={<Button />}>Trigger</Tooltip.Trigger>
<Tooltip.Content side="right" align="start">
Appears on the right
</Tooltip.Content>
</Tooltip.Root>
);
}Shared Delay with Provider
Use Tooltip.Provider to avoid tooltips opening immediately in dense UIs like toolbars:
Hover a help button and wait for the initial 600 ms delay, then move directly to its neighbor. Once a tooltip is visible, the provider's shared timeout lets adjacent tooltips open immediately. Keyboard focus also reveals the help.
tsx
function SharedDelay() {
const fields = [
{ name: "Name", help: "Use a name teammates recognize." },
{ name: "Email", help: "Use the address for order updates." },
{ name: "Role", help: "Choose the permissions this person needs." },
];
return (
<div className="space-y-3">
<Text.p>Hover the first button for 600 ms, then move directly to another.</Text.p>
<Tooltip.Provider delay={600}>
<div className="flex gap-2" role="group" aria-label="Shared-delay help">
{fields.map((field) => (
<Tooltip.Root key={field.name}>
<Tooltip.Trigger render={<Button variant="outline" />}>
{field.name} help
</Tooltip.Trigger>
<Tooltip.Content>{field.help}</Tooltip.Content>
</Tooltip.Root>
))}
</div>
</Tooltip.Provider>
</div>
);
}Examples
Icon Button with Tooltip
tsx
function IconButton() {
return (
<Tooltip.Root>
<Tooltip.Trigger render={<Button size="icon" variant="ghost" />}>
<PencilIcon />
<span className="sr-only">Edit</span>
</Tooltip.Trigger>
<Tooltip.Content>Edit order</Tooltip.Content>
</Tooltip.Root>
);
}Controlled Tooltip
Use Show tooltip and Hide tooltip to set the open state from outside the trigger. Explicit actions avoid toggling twice when the tooltip also dismisses on an outside press. Hovering or focusing Details target updates the same controlled state, reflected in the status text.
tsx
function ControlledTooltip() {
const [open, setOpen] = useState(false);
return (
<div className="space-y-3">
<div className="flex gap-2">
<Button type="button" variant="outline" onClick={() => setOpen(true)}>
Show tooltip
</Button>
<Button type="button" variant="outline" onClick={() => setOpen(false)}>
Hide tooltip
</Button>
<Tooltip.Root open={open} onOpenChange={setOpen}>
<Tooltip.Trigger render={<Button variant="ghost" />}>Details target</Tooltip.Trigger>
<Tooltip.Content>Additional details here</Tooltip.Content>
</Tooltip.Root>
</div>
<Text.p role="status">Tooltip: {open ? "open" : "closed"}</Text.p>
</div>
);
}Accessibility
- Tooltip content is rendered in a portal
- Trigger receives focus and keyboard activation support
sr-onlytext on icon-only triggers is recommended for screen readers
Related Components
- Button - Common trigger element for tooltips