Components / Overlays
Tooltip
Short supplementary text for a control, shown on hover or keyboard focus. It becomes the trigger's accessible description. For an icon-only button, IconButton already shows its label as a tooltip.
When to useLink to "When to use"
- A hint that explains a control, such as a shortcut or what an action exports.
- Extra detail the user can do without.
Use something else when:
- the text is essential to using the control: put it in a visible label or
description - the content is interactive or long: a popover or dialog
- the control is an icon-only button: IconButton, which requires a label
UsageLink to "Usage"
import { Button, Tooltip } from "@arshad-shah/cynosure";
import { download } from "@arshad-shah/cynosure/icons";
<Tooltip content="Download as JSON">
<Button icon={download}>Export</Button>
</Tooltip>
<Tooltip content="Copy link" placement="bottom" delay={500}>
<Button variant="ghost">Share</Button>
</Tooltip>The child must be one focusable element (a Button, IconButton or Link). Keep content short and non-interactive.
PlacementLink to "Placement"
placement is top (default), bottom, start or end. The tooltip flips and shifts to stay in the viewport, and follows its trigger on scroll and resize.
TimingLink to "Timing"
Hover opens after delay milliseconds (default 300). Keyboard focus opens it immediately.
Sometimes, or for the eye onlyLink to "Sometimes, or for the eye only"
disabled turns the tooltip off without remounting its trigger, for a tooltip that only matters some of the time, such as the full text of a label while it is cut short. describe={false} is for a tip that repeats the trigger's own name (that same cut-short label): it still shows, but screen readers, which already hear the name, are not read it again as a description. whenTruncated does both for the full text of a label: the tip is on only while the text is cut short (measured after every render and, with one ResizeObserver, whenever its box is resized), and it never describes the trigger. Pass true to measure the trigger, or a function that picks the element inside it holding the text. Tabs, StatusBar and DataGrid use it.
PropsLink to "Props"
| Prop | What it does | Type | Default |
|---|---|---|---|
contentRequired | Short supplementary text; it becomes the trigger's accessible description. | ReactNode | |
childrenRequired | One focusable element (Button, IconButton, Link…). | ReactElement<Record<string, unknown>, string | JSXElementConstructor<any>> | |
placement | Preferred side; flips when it does not fit. Default "top". | Placement | "top" |
delay | Hover delay in ms (focus opens immediately). | number | |
className | Added to the element around the trigger (the anchor, the box the parent lays out), for layout: a grid area, flex, margins. | string | |
disabled | Turn the tooltip off without remounting the trigger: no tip, no description, hover and focus do nothing. For a tooltip that only matters sometimes, such as the full text of a label while it is cut short. | boolean | |
describe | false when the tip only repeats text the trigger's name already holds, such as a label cut short with an ellipsis: it is shown but hidden from assistive technology, and does not describe the trigger. Default true. | boolean | true |
whenTruncated | Show the tip only while text is cut short (it overflows its box, as with an ellipsis), for the full text of a label: true measures the trigger, a function picks the element inside it that holds the text. It is measured after every render and whenever the element is resized, and the tip repeats the trigger's name, so it implies describe={false}. | boolean | ((trigger: HTMLElement) => HTMLElement | null) |
Generated from the type definitions in @arshad-shah/cynosure 0.5.0.
Behaviour and accessibilityLink to "Behaviour and accessibility"
| Input | Result |
|---|---|
| Hover | Opens after delay, closes shortly after the pointer leaves |
| Keyboard focus | Opens immediately |
| Escape | Dismisses it |
- WCAG 1.4.13: the tooltip is hoverable, dismissible with Escape, and stays while hovered or focused.
- Description: the trigger gets
aria-describedbypointing to the tooltip, and any existing value is kept. - Top layer: it uses the Popover API, so it is never clipped and works inside shadow roots.
TouchLink to "Touch"
It never opens on touch. Do not rely on a tooltip for information touch users need.
ThemingLink to "Theming"
Tokens: --cy-tooltip-{bg,ink,radius,max-width}.
createTheme({ components: { tooltip: { radius: "6px", maxWidth: "240px" } } });RelatedLink to "Related"
IconButton · Button · Link
These examples run Cynosure 0.5.0 (commit 50ce30b), the version on npm.