import { Tooltip } from "@senvenli/react/overlay";Examples
With a shortcut
The key that does the same thing, as a chip.import { Button } from "@senvenli/react/action";
import { Tooltip } from "@senvenli/react/overlay";
export default function Example() {
return (
<Tooltip content="Filter" shortcut="F">
<Button iconOnly iconBefore="list-filter" aria-label="Filter" />
</Tooltip>
);
}Placement
Above by default; it flips when there is no room.import { Button } from "@senvenli/react/action";
import { Stack } from "@senvenli/react/layout";
import { Tooltip } from "@senvenli/react/overlay";
const PLACEMENTS = ["top", "bottom", "start", "end"] as const;
export default function Example() {
return (
<Stack direction="horizontal" space="space-100">
{PLACEMENTS.map((placement) => (
<Tooltip key={placement} content={`Placed at the ${placement}`} placement={placement}>
<Button>{placement}</Button>
</Tooltip>
))}
</Stack>
);
}Readable on touch
With openOnTouch a tap opens it, for a status that has no action of its own.import { Badge } from "@senvenli/react/display";
import { Tooltip } from "@senvenli/react/overlay";
export default function Example() {
return (
<Tooltip content="Waiting for the bank to confirm the payment" openOnTouch>
<Badge tone="warning">Payment pending</Badge>
</Tooltip>
);
}Guidelines
When to use it
- Naming an icon button or adding a short hint.
Use something else when
- The content is interactive or long. Popover
- The hint is rich content, such as a profile, and opens from a link. Hover card
Accessibility
Built in
- Opens on keyboard focus too; touch users can tap with openOnTouch.
You provide
- Content that is a hint, never the only place important information lives.
API reference
Tooltip
| Prop | Type | Default | Description |
|---|---|---|---|
contentRequired | string | – | Plain text only: the same words as the control's |
childrenRequired | ReactElement<unknown, string | JSXElementConstructor<any>> | – | The trigger. It must be focusable; a non-interactive element (a truncated lozenge) is made focusable. |
placement | Placement | – | |
shortcut | string | – | A keyboard shortcut shown as a chip ("F"). |
openOnTouch | boolean | – | Readable on touch screens: a tap on the trigger opens the tooltip and a second tap closes it; a tap anywhere else, or Esc, closes it. Mouse hover and keyboard focus work exactly as without it. For a trigger that does nothing on its own (a country flag, a truncated value); on a button the tap still presses it. |
motion | ComponentMotion | – |
|
contentRequiredstringPlain text only: the same words as the control's
aria-label, or a truncated value in full.childrenRequiredReactElement<unknown, string | JSXElementConstructor<any>>The trigger. It must be focusable; a non-interactive element (a truncated lozenge) is made focusable.
placementPlacementshortcutstringA keyboard shortcut shown as a chip ("F").
openOnTouchbooleanReadable on touch screens: a tap on the trigger opens the tooltip and a second tap closes it; a tap anywhere else, or Esc, closes it. Mouse hover and keyboard focus work exactly as without it. For a trigger that does nothing on its own (a country flag, a truncated value); on a button the tap still presses it.
motionComponentMotionauto(follow the device),reduceornone, for this component; the provider's setting otherwise.