Tooltip
A short description of a control, on hover and on focus.
Examples
Playground
Copies the hex value to the clipboard
Placement
Hover or focus each. `top` by default; `bottom` for a trigger at the top of the viewport.
top
Copies the hex value to the clipboard
bottom
Copies the hex value to the clipboard
Content
A long tooltip wraps at the tooltip width rather than running across the page.
Copies the value in the format the export settings name, which is hex unless the workspace changed it
On focus
Tab to Copy: the tooltip shows on focus with no delay, and Escape dismisses it.
Copies the hex value to the clipboard
Install
npx shadcn add @hipuku/tooltipUsage
import { Tooltip } from '@/components/haus/components/Tooltip'
<Tooltip content="Copy link">
<IconButton icon={<LinkIcon />} label="Copy link" />
</Tooltip>API
Tooltip also takes its element's own attributes and forwards its ref. className lands on the
wrapper.
| Prop | Type | Description |
|---|---|---|
contentrequired | string | The text. A string rather than a node, and that is a constraint on purpose: a tooltip that can hold a link or a button is a Popover, and the moment it holds one the WCAG 1.4.13 contract below stops being satisfiable. |
placement | "top" | "bottom" | |
delay | number | Milliseconds to wait before showing on hover. Never applied to focus: a keyboard user has already committed to the element, and a delay there is just a description that arrives late. Zero by default. A delay is a judgement about a particular density of UI, and a design system guessing 400ms for everybody is a number every consumer ends up overriding. |
childrenrequired | React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | The element the tooltip describes. Exactly one, and it must be able to
take focus: a tooltip on a <span> is invisible to every user who is not
using a mouse. |
Placement and timing
placement is top by default, or bottom for a control near the top of the screen. delay
waits before showing on hover; it never delays focus.
A tooltip is never the only place information lives: touch has no hover. And it holds a short string only. If it needs a link, a control or more than a line, use Popover.
Accessibility
- Shows on keyboard focus as well as on hover. The child must be focusable.
- The child is described by the tooltip's text, which is added to its
aria-describedby. - Escape hides it without moving focus. The pointer can move onto it, and it stays until the pointer or focus leaves, with no timeout.