Tooltip
A short label that appears when the pointer rests on something. Use it to supplement a control that shows only an icon.
import { Button, Tooltip } from 'neba';
<Tooltip content="Copy the deploy URL">
<Button variant="outline" startIcon={<LinkIcon />} />
</Tooltip>;Props
| Prop | Type | Default | Description |
|---|---|---|---|
| content * | ReactNode | — | What it says. A short phrase: a tooltip cannot be reached by touch and nothing inside it can be clicked |
| children * | ReactElement | — | The single element it hangs off. The trigger merges onto it rather than wrapping it, so the layout gains no element |
| sizeshared | 'xs' | 'sm' | 'md' | 'lg' | 'xl' | 'sm' | The plate's type scale and padding |
| colorshared | 'primary' | 'secondary' | 'success' | 'warning' | 'danger' | 'info' | 'secondary' | Colour family. A tooltip is always a note about something else, so the neutral family is the honest default |
| densityshared | 'default' | 'compact' | 'default' | Padding only |
| side | 'top' | 'right' | 'bottom' | 'left' | 'top' | Which edge of the trigger it appears on. Flips to the opposite side when there is no room |
| align | 'start' | 'center' | 'end' | 'center' | Where it sits along that edge |
| sideOffset | number | 6 | Distance from the trigger, in pixels |
| delay | number | 600 | How long the pointer has to rest before it opens, in ms |
| closeDelay | number | 0 | How long it waits before closing, in ms |
| arrow | boolean | true | The little wedge pointing at the trigger |
| open | boolean | — | Whether it is open. With onOpenChange |
| defaultOpen | boolean | false | The initial state of an uncontrolled tooltip |
| onOpenChange | (open: boolean) => void | — | Called when it opens or closes |
| disabled | boolean | false | Stops it opening without disabling the trigger: for the tooltip that only exists while a label is truncated |
Native <div> attributes pass through to the popup. Only color, content and children are excluded, since the table above spells them differently.
The trigger merges onto children rather than rendering a box of its own, so the tooltip costs the layout nothing. children must be a single element that accepts a ref and spreads props: every Neba component does.
Examples
side and align
side is where the popup sits relative to the trigger; align is its alignment along that axis. The side flips automatically when there is no room at the window edge. sideOffset sets the gap and arrow draws a pointer.
delay and TooltipProvider
delay is how long the pointer must rest before opening; closeDelay is how long the tooltip stays after it leaves.
Wrapping tooltips in a TooltipProvider makes them share the delay: once one has opened, its neighbours open instantly, and the delay comes back after a pause. That way a row of icon buttons does not make you wait at every stop.
Accessibility
- The popup carries
role="tooltip", and the trigger getsaria-describedbypointing at it only while it is open. - A tooltip is a description, never a name. Give an icon-only button its own
aria-label. - It opens on keyboard focus but not on focus that arrived from a click, and closes on Escape.
- On a touch screen it cannot be reached by pointer, and anything clickable inside it cannot be clicked. Use a popover if you need either.