Tooltip
A short text that appears next to an element on hover and focus.
Usage
Wrap the element. The tooltip shows on hover and when anything inside has focus.
tsx
<Tooltip content="copy to clipboard">
<Button aria-label="copy" onClick={handleCopy}>
<Button.Icon><MdContentCopy /></Button.Icon>
</Button>
</Tooltip>copy to clipboard
Position
tsx
<Tooltip content="save" placement="top">…</Tooltip>
<Tooltip content="delete" placement="right">…</Tooltip>save
delete
Only when there is something to say
There is no open prop: with empty content the tooltip never shows. Pass a value only when you need it, like an error.
tsx
<Tooltip content={error}>
<Field value={value} />
</Tooltip>For screen readers
tsx
<Tooltip id="save-hint" content="saves without closing">
<Button aria-describedby="save-hint">
<Button.Label>save</Button.Label>
</Button>
</Tooltip>Reference
| prop | type | default | |
|---|---|---|---|
as? | ElementType | "div" | the anchor element |
children? | ReactNode | — | what the tooltip is anchored to |
content? | ReactNode | — | the text; null or undefined keeps it hidden |
placement? | "top" | "right" | "bottom" | "left" | "bottom" | the side it appears on |
label? | string | — | aria-label of the bubble while it is empty |
id? | string | — | id of the bubble, for aria-describedby |
…rest | props of as | — | typed against the chosen element |