Tooltip
Web/MobileA popup that displays information related to an element when it receives keyboard focus or hover.
Installation
pnpm dlx cubix-ui@latest add tooltipAdd the Provider
Place TooltipProvider near the root of your app so tooltips share one open delay. It is optional: without it every tooltip opens immediately.
import type { ReactNode } from "react"
import { TooltipProvider } from "@/components/cubix/tooltip"
export default function RootLayout({ children }: { children: ReactNode }) {
return (
<html lang="fa" dir="rtl">
<body>
<TooltipProvider>{children}</TooltipProvider>
</body>
</html>
)
}Usage
import { Button } from "@/components/cubix/button"
import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/cubix/tooltip"
<Tooltip>
<TooltipTrigger render={<Button variant="outline" size="sm" />}>نگه دارید</TooltipTrigger>
<TooltipContent>افزودن به کتابخانه</TooltipContent>
</Tooltip>
Composition
The tooltip opens on hover and on keyboard focus, and closes on Escape. It starts right-to-left and follows the closest dir on the page; pass dir to Tooltip to override it.
TooltipProvider (optional)
└── Tooltip
├── TooltipTrigger
└── TooltipContentExamples
Side
Use side to choose where the tooltip appears. Prefer the logical values inline-start and inline-end: in RTL, inline-start is the right side of the trigger.
Icon button
Give an icon-only trigger an aria-label so it has an accessible name for screen readers.
With keyboard shortcut
Put a Cubix Kbd inside the content to show the shortcut for an action.
Disabled button
A disabled button can't be hovered or focused, so render the trigger as a span with tabIndex={0}. The tooltip then opens on hover and on keyboard focus.
Delay
Pass delay to a single Tooltip, or to TooltipProvider to set a shared open delay for the tree.
API Reference
TooltipProvider
Optional. Shares one open delay between every tooltip in the tree.
| Prop | Type | Default | Description |
|---|---|---|---|
| delay | number | 0 | Default delay in milliseconds before any tooltip in the tree opens. Without a provider, tooltips open immediately. |
| children | React.ReactNode | - | Tooltip trees that share this delay setting. |
Tooltip
The container that wraps the trigger and content and manages open state.
| Prop | Type | Default | Description |
|---|---|---|---|
| dir | "ltr" | "rtl" | closest page dir, else rtl | Text direction of the trigger and tooltip. Defaults to the closest dir on the page, and to right-to-left when there is none. |
| open | boolean | - | Controlled open state. Omit to use uncontrolled mode. |
| defaultOpen | boolean | false | Initial open state when uncontrolled. |
| onOpenChange | (open: boolean) => void | - | Called when the open state changes. |
| delay | number | TooltipProvider delay, else 0 | Delay in milliseconds before this tooltip opens. Overrides TooltipProvider. |
| children | React.ReactNode | - | The trigger and content elements. |
TooltipTrigger
The element that opens the tooltip on hover and focus. Compose it with Cubix Button via render.
| Prop | Type | Default | Description |
|---|---|---|---|
| render | React.ReactElement | - | Render the trigger as another element (for example a Button). |
| className | string | - | Additional Tailwind classes merged with the component styles (last one wins). |
TooltipContent
The popup rendered in a portal, positioned relative to the trigger.
| Prop | Type | Default | Description |
|---|---|---|---|
| side | "top" | "right" | "bottom" | "left" | "inline-start" | "inline-end" | "top" | Preferred side of the trigger to render the tooltip on. |
| sideOffset | number | 4 | Distance in pixels between the trigger and the tooltip. |
| align | "start" | "center" | "end" | "center" | Alignment of the tooltip relative to the trigger. |
| alignOffset | number | 0 | Offset in pixels along the alignment axis. |
| className | string | - | Additional Tailwind classes merged with the component styles (last one wins). |