Loading component…
Loading component…
A small dark label for one control
To reuse this local React demo, copy all files from the Code tab into the same folder, then import Tooltip from ./tooltip.
import { Search01Icon } from "@hugeicons/core-free-icons";
import { Tooltip } from "@/components/ui/tooltip";
import { IconButton } from "@/components/ui/icon-button";
export function SearchTool({ onSearch }: { onSearch: () => void }) {
return (
// One child element: the Tooltip clones it and adds its handlers, ref and aria-describedby
<Tooltip content="Search runs" shortcut="⌘K" side="bottom">
{/* title="" leaves out the Icon Button's own browser tooltip */}
<IconButton variant="secondary" icon={Search01Icon} label="Search runs" title="" onClick={onSearch} />
</Tooltip>
);
}| Name | Type | Default | Description |
|---|---|---|---|
| content | ReactNode | The label – a few words, wraps at 240px. Text only: never a link or button inside. Empty or null renders the child alone | |
| shortcut | string | A keyboard shortcut after the label, in a small key chip, e.g. "⌘K" or "⇧⌘S" | |
| children | ReactElement | Exactly one element that takes a ref and focus – a button, a link, an Icon Button. Its own handlers and ref keep working; they run first, and preventDefault in one stops the tooltip's | |
| side | "top" \| "bottom" \| "left" \| "right" | "top" | Where it shows; flips to the other side when that has more room, and goes above or under when there is no room beside it |
| align | "start" \| "center" \| "end" | "center" | Which edges line up; above and under, start is the left (the right in RTL). Pushed inside the window when it would stick out |
| offset | number | 6 | Gap to the trigger in px |
| delay | number | 500 | How long the pointer rests on the trigger before it shows, in ms. Keyboard focus, and a neighbour within 300ms of the last one, show it at once |
| disabled | boolean | false | Never shows it – e.g. when the label is not cut off |
| open | boolean | Controls it from outside, with onOpenChange; leave it out and it opens on its own | |
| onOpenChange | (open: boolean) => void | Called whenever it wants to open or close | |
| className | string | A class for the label |
It lives in the top layer (popover), so a card's overflow or z-index never cuts it; it follows its trigger on scroll and resize
Always on screen: it flips sides and is pushed inside the window; long text wraps at 240px (never wider than the window)
A label in another script reads in its own direction (dir="auto")
Dark mode built in: a light label on dark pages – switches when an ancestor (usually <html>) has the class dark or data-theme="dark"
@import "tailwindcss"; in your main CSS file.