Skip to content
Cynosurev0.5.0
SearchStorybookGitHubnpmColour mode: System. Switch to Light

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.

Hover shows after delay

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"

tsx
Copy
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.

Flips near the viewport edge

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.

Only while the text is cut short

PropsLink to "Props"

Every prop of Tooltip
PropWhat it doesTypeDefault
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.booleantrue
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"

Behaviour and accessibility, table 1
InputResult
HoverOpens after delay, closes shortly after the pointer leaves
Keyboard focusOpens immediately
EscapeDismisses it
  • WCAG 1.4.13: the tooltip is hoverable, dismissible with Escape, and stays while hovered or focused.
  • Description: the trigger gets aria-describedby pointing 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}.

ts
Copy
createTheme({ components: { tooltip: { radius: "6px", maxWidth: "240px" } } });

IconButton · Button · Link

These examples run Cynosure 0.5.0 (commit 50ce30b), the version on npm.

Getting started
Theming
Icons
Accessibility
Code editors and highlighters
Using Cynosure without React
Build-tool adapters
Components
Accordion
AppShell
AspectRatio
Breadcrumbs
Calendar
Card
Container
Disclosure
Divider
DocumentViewport
Grid
Inline
PageHeader
PanZoomCanvas
ScrollArea
SideNav
SortableList
SplitPane
Stack
StatusBar
Tabs
TitleBar
Toolbar
Tree
VirtualList
ZoomControls
Announcer
Avatar
Badge
CodeBlock
DescriptionList
EmptyState
ErrorBoundary
Field
Heading
IconTile
Image
Kbd
List
LoadingDots
Notice
ProgressBar
Prose
Skeleton
Stat
Steps
Table
Text
Button
Checkbox
Checklist
ColorField
ColorSwatches
Combobox
CompareSlider
CopyButton
DateField
FileDrop
IconButton
KeyValueEditor
Link
NumberField
Pagination
PathField
RadioGroup
SearchField
SegmentedControl
Select
SelectionFrame
SignaturePad
Slider
Switch
TagInput
TextArea
TextField
ThemeToggle
TimeField
ButtonBase
ChoiceBase
DialogBase
FileInputBase
HiddenValue
Icon
InputBase
LinkBase
LiveRegion
TextAreaBase
ChatMessage
Choice
DataGrid
DeviceFrame
HighlightedText
HotkeyField
ListRow
OptionList
OverlayFrame
QRCode
RowActions
Section
SiteFooter
SiteHeader
SkipLink
SortButton
VisuallyHidden
CommandPalette
ContextMenu
Dialog
FloatingToolbar
HoverCard
Menu
Menubar
Popover
ProgressOverlay
Sheet
Toast
Tooltip
Changelog