When to use it#
- Use a tooltip to show the name of an icon-only control and its shortcut, for example in a toolbar or an editor.
- Use it for a short extra hint that is nice to have, never for what a user needs to finish a task: touch users never see a tooltip.
- Not for text with a link, a button or a field: use a Popover. A tooltip disappears with the pointer and the focus, so nothing in it can be reached with Tab.
- Not for an error or an important message: write it as visible text.
- Not on a button that is natively disabled: it gets no pointer events and no focus, so the tooltip never shows. Keep the button focusable and say why it is off in visible text.
Example#
import { Button, Icon, Tooltip } from '@kvirn-ui/react'
import { useTooltipTexts } from './texts.ts'
export function DefaultTooltip() {
const { texts } = useTooltipTexts()
return (
<Tooltip.Root>
<Tooltip.Trigger as={Button} className="kv-button--icon-only" aria-label={texts.search}>
<Icon name="search" />
</Tooltip.Trigger>
<Tooltip.Popup>
<Tooltip.Name>{texts.search}</Tooltip.Name>
</Tooltip.Popup>
</Tooltip.Root>
)
}Use cases#
A name and a shortcut
Show the key that does the same thing. The name is hidden from assistive technology and the shortcut is the button’s description, so a screen reader says the name once, then the shortcut. Set aria-keyshortcuts on the button too, and handle the key in your app: the tooltip only shows it.
import { Button, Icon, Kbd, Tooltip } from '@kvirn-ui/react'
import { useTooltipTexts } from './texts.ts'
export function WithAShortcut() {
const { texts } = useTooltipTexts()
return (
<Tooltip.Root>
<Tooltip.Trigger
as={Button}
className="kv-button--icon-only"
aria-label={texts.undo}
aria-keyshortcuts="Control+Z"
>
<Icon name="arrow-back" />
</Tooltip.Trigger>
<Tooltip.Popup>
<Tooltip.Name>{texts.undo}</Tooltip.Name>
<Tooltip.Shortcut>
<Kbd>
<Kbd>Ctrl</Kbd>+<Kbd>Z</Kbd>
</Kbd>
</Tooltip.Shortcut>
</Tooltip.Popup>
</Tooltip.Root>
)
}Props in this example:
ason Tooltip.Trigger
Warning: Don't forget
Give the control a name of its own, with aria-label from your translations, and start the tooltip with the same text. Then a person using voice control can say what they see (2.5.3 Label in Name). See What you need to do.
A little extra information
Plain text in the popup becomes the button’s description. Use it for something the name does not say, such as what will happen. Keep it short, and never put anything in it that a user needs.
import { Button, Icon, Tooltip } from '@kvirn-ui/react'
import { useTooltipTexts } from './texts.ts'
export function ExtraInformation() {
const { texts } = useTooltipTexts()
return (
<Tooltip.Root>
<Tooltip.Trigger as={Button} className="kv-button--icon-only" aria-label={texts.print}>
<Icon name="document" />
</Tooltip.Trigger>
<Tooltip.Popup>{texts.printDescription}</Tooltip.Popup>
</Tooltip.Root>
)
}A toolbar of icon buttons
Every button has its own tooltip. Once one has opened, the next one opens at once, so a user moving along the row with the mouse or the arrow keys does not wait for each.
import { Icon, Toolbar, Tooltip } from '@kvirn-ui/react'
import { useTooltipTexts } from './texts.ts'
export function IconToolbar() {
const { texts } = useTooltipTexts()
const tools = [
{ name: texts.undo, icon: 'arrow-back' as const },
{ name: texts.redo, icon: 'arrow-forward' as const },
{ name: texts.print, icon: 'document' as const },
]
return (
<Toolbar.Root aria-label={texts.group}>
{tools.map((tool) => (
<Tooltip.Root key={tool.name}>
<Tooltip.Trigger
as={Toolbar.Button}
className="kv-button--icon-only"
aria-label={tool.name}
>
<Icon name={tool.icon} />
</Tooltip.Trigger>
<Tooltip.Popup>
<Tooltip.Name>{tool.name}</Tooltip.Name>
</Tooltip.Popup>
</Tooltip.Root>
))}
</Toolbar.Root>
)
}Props in this example:
ason Tooltip.Trigger
Information: Did you know?
Tooltips share one delay for the whole page. Make a separate group with createTooltipGroup() from @kvirn-ui/core when a part of the page should keep its own.
Slower, and below the button
Hover opens a tooltip after half a second, and keyboard focus opens it at once. Change the delay when tooltips would flash over a dense row, and the side when there is more room below.
import { Button, Icon, Tooltip } from '@kvirn-ui/react'
import { useTooltipTexts } from './texts.ts'
export function Timing() {
const { texts } = useTooltipTexts()
return (
<Tooltip.Root delay={1000} closeDelay={300} placement="bottom">
<Tooltip.Trigger as={Button} className="kv-button--icon-only" aria-label={texts.search}>
<Icon name="search" />
</Tooltip.Trigger>
<Tooltip.Popup>
<Tooltip.Name>{texts.search}</Tooltip.Name>
</Tooltip.Popup>
</Tooltip.Root>
)
}Props in this example:
delayon Tooltip.RootcloseDelayon Tooltip.Rootplacementon Tooltip.Root
Accessibility#
What it does for you#
- APG pattern: Tooltip (APG marks it as a work in progress, and AT support for
role="tooltip"varies, so the trigger is complete without it), and WCAG 1.4.13 Content on Hover or Focus (AA). - Deviations: none from the APG keyboard practice. Two decisions: the part of the tooltip that repeats the trigger's name is
aria-hiddenand only the shortcut is the description (so a screen reader hears the name once and learns the shortcut), andpopover="manual"rather thanpopover="hint", so a tooltip never light-dismisses an open Popover. - Native elements used:
<div popover="manual" role="tooltip">(Popup),<span>(Name, Shortcut). The Trigger is the consumer's own control: a<button>by default, or any focusable control throughas(Toolbar.Toggle,Button,Toolbar.Item). Nothing for Root: it renders no element.
A Tooltip tells a sighted user what an icon-only control does, and its shortcut ("Bold Ctrl+B"), without pressing it. It shows when the pointer rests on the control and at once when the control has keyboard focus. A magnifier user can move the pointer onto it, anyone can hide it with Escape, and a screen reader user hears the control's name once. A tooltip is never the only name, and never holds anything the user must read or do: it names a control and adds a shortcut. Anything more is visible text or a Popover.
| Part | Element / role | ARIA / state | Notes |
|---|---|---|---|
| Tooltip.Root | none: it renders no element | none | Owns the open state: open / defaultOpen / onOpenChange(open, { reason }), placement (top), offset (4), padding (8), delay (500), closeDelay (100) and group. Reasons: hover, focus, escape, pointer-leave, blur, trigger-press. Works out the trigger's description from the parts it holds |
| Tooltip.Trigger | <button type="button">, or the control as gives | aria-describedby (the popup, or its shortcut part, joined with the consumer's own). Its own name, role and states are untouched | Never gets a class or a state of its own: its look never depends on its tooltip. The anchor the popup is placed against. A dev warning when it has no accessible name of its own (4.1.2, 2.5.3) |
| Tooltip.Popup | <div popover="manual" role="tooltip">, always rendered | id. No name, never focusable. aria-hidden="true" when it has a Name and no Shortcut. data-open while open, data-placement (top, bottom, …) | Class kv-tooltip. Hidden by the browser while closed (display none), so aria-describedby resolves before it opens. The script sets its position and size. Right after the trigger in the DOM. A dev warning when it holds interactive content |
| Tooltip.Name | <span> | aria-hidden="true" | Class kv-tooltip-name. The part that repeats the trigger's name, hidden so the name is heard once and not read again in browse mode while the tooltip is open. A popup with a Name and no Shortcut adds no description to the trigger, and is itself aria-hidden |
| Tooltip.Shortcut | <span> | id: the trigger's aria-describedby | Class kv-tooltip-shortcut. Adds information, such as the shortcut (Kbd for keys). Read after the name: "Bold, toggle button, not pressed, Ctrl+B". Left to right, because key names are Latin script |
useTooltip | the same attributes, for your own elements | triggerProps, popupProps, nameProps, shortcutProps, isOpen, placement | Options as the Root, and description: 'popup' | 'shortcut' | 'none' (what the trigger's aria-describedby points at). The trigger's ref is a callback ref: mergeProps merges yours. Join your own aria-describedby with the hook's, don't replace it |
Rules, tested in tooltip.test.tsx and tooltip-machine.test.ts:
- Name versus description. Plain text in the Popup is the trigger's description as a whole (APG). A
Tooltip.Nameis hidden from assistive technology, aTooltip.Shortcutis the description. With both, a screen reader hears the name once. With a Name alone the tooltip adds nothing for assistive technology: the trigger has no description, and the whole popup isaria-hidden="true"(itsrole="tooltip"stays), because an openrole="tooltip"whose only content is hidden has no accessible text (axearia-tooltip-name). With a Shortcut or plain text the popup is notaria-hiddenand only the Name line is. The popup is in the DOM while closed in every case. The trigger keeps its ownaria-keyshortcutsas well (the consumer sets it): a screen reader that announces both may read the shortcut twice, which the AT matrix checks. - Always in the DOM. The Popup is rendered while closed and hidden by the browser (
popoverclosed isdisplay: none), so the reference always resolves. - Top layer.
popover="manual": it never closes an open Popover by light dismiss, and the platform closes nothing.showPopover()andhidePopover()are called when it opens and closes. - Placement. Above the trigger (
top), centred, with a small gap, flipping below when there is no room, and shifted along the inline axis to stay inside the viewport. Wide and tall enough, it never covers its trigger (2.4.11 Focus Not Obscured (Minimum), AA); in a viewport shorter than the tooltip needs it can, and Escape hides it. While the trigger is scrolled out of view the popup is hidden (data-detached) and returns with it. - Opening. Hover: the pointer rests on the trigger for
delay(500 ms). Keyboard focus: at once, when the focus shows a focus ring (:focus-visible), so a click does not open it. The next tooltip opens at once when one is open or closed less than 300 ms ago (agroupshared by the page, or by thegroupyou give), and a group shows one tooltip at a time. A touch pointer opens nothing: nothing needed is only in a tooltip. - Staying (1.4.13 persistent). It stays while the pointer is on the trigger or the tooltip, or the trigger has keyboard focus. It has no timeout. Enter and Space on the trigger don't close it: focus is still there and the text is still true.
- Hoverable (1.4.13). After the pointer leaves, it waits
closeDelay(100 ms) before closing, which covers the gap; the pointer reaching the tooltip cancels it, and the tooltip stays while the pointer is on it. The tooltip always receives pointer events. - Closing. Escape; the pointer leaving the trigger and the tooltip; blur; a pointer press on the trigger; and while the trigger's own popup is open (
aria-expanded="true"on it: a Popover, a Listbox), when it closes and stays closed. - Dismissable (1.4.13). Escape hides it without moving the pointer or focus, through the dismissable layer stack: the tooltip is the innermost layer, so an open Popover underneath stays open (an open Listbox or Combobox with focus handles Escape in its own key handler first: see Known issues), and the next Escape closes that. After Escape it stays hidden until the pointer leaves and comes back, or focus leaves and comes back (each source separately). Escape with no tooltip open is not handled and not prevented.
- Controlled.
openwithonOpenChange: the tooltip shows theopenit is given, and reports every request. A request the owner refuses leaves it as it was. - Server rendering. Nothing reads
windowwhile rendering: the server writespopover,role,id,data-placementand no inline position. Everything else happens in effects. as.Tooltip.Triggertakes a component (as={Button},as={Toolbar.Toggle}) that must be focusable and spread its props on a DOM node; its props are plain props, merged with the tooltip's (handlers chain,classNamejoins, refs merge) and the consumer's ownaria-describedbyis joined with the tooltip's. Allowed elements:Tooltip.Namespan(default) orstrong;Tooltip.Shortcutspan(default) orsmall; another tag warns once and falls back.Tooltip.Popuphas noas: it is apopoverelement with a fixed role.- Dev warnings: a Trigger with no accessible name of its own, a Popup with interactive content, and a part outside a Root.
It announces nothing.
What you need to do#
- Give the trigger a name of its own, with
aria-labelfrom your translations for an icon-only control, or visible text. A tooltip is never the only name: it isn't shown on touch, and its text is not the control's name. A dev warning fires without one (4.1.2, 2.5.3). - Start the tooltip with the trigger's name, from the same translation, so a voice-control user can say what they see (2.5.3). Wrap it in
Tooltip.Name, so a screen reader doesn't read it twice. - Put the shortcut in
Tooltip.Shortcut(withKbdfor keys) and set the trigger'saria-keyshortcuts. Key names aren't translated. - Text and keys only. Never a link, a button, a field or a heading: a tooltip disappears with the pointer and the focus, and can't be reached with Tab. A dev warning fires. Use a Popover for anything the user can act on.
- Never put essential information in a tooltip. Anything a user needs to finish a task is visible text. The editor's
labels="icon-and-text"shows names as text. - Render the Popup right after the Trigger, in the same parent.
- No
titleattribute on the trigger next to a tooltip: it isn't shown on keyboard focus or touch, can't be hovered or dismissed (1.4.13), and next toaria-labelit is announced twice. - No tooltip on a natively
disabledbutton: it gets no pointer events and no focus. Usearia-disabled(toolbar items always do) if the name must stay discoverable. - Everything in the trigger's own contract (
button.a11y.md,toggle.a11y.md) applies to the trigger.
Warning: Don't forget
Don’t add a title attribute to the control next to a tooltip. The browser’s own tooltip can’t be hovered or dismissed (1.4.13 Content on Hover or Focus), and with aria-label it is read twice.
Visual and modes#
- Focus indicator: the trigger's own. The tooltip is never focusable and has no ring.
- Target size: not applicable: the tooltip isn't a control. It is hoverable, which needs no target size.
- Colour: the text has at least 4.5:1 contrast against the tooltip's background in every theme (1.4.3 Contrast (Minimum), AA), checked by the theme's contrast check. The tooltip's edge is a decorative hairline: 1.4.11 Non-text Contrast (AA) doesn't apply to the box, and its content is text.
- forced-colors behaviour: the system's background and text colours, a thin edge in the text colour, and no shadow. The keys keep their edge.
- reduced-motion behaviour: a short fade in, only when the user has not asked for reduced motion. No movement, no scale. Closing is instant in every setting.
- Reflow, text spacing: the tooltip is at most 20rem wide and never wider than the viewport minus 8px each side, so long text wraps and the tooltip grows in height, not width, and has no fixed height (1.4.10 Reflow, AA; 1.4.12 Text Spacing, AA: the reflow sweep runs every story at 320 CSS px and fails on horizontal overflow; the text-spacing sweep applies the 1.4.12 spacing to every story and fails on a box that clips more content than it holds). The text is never clipped. In a viewport too short for a long tooltip (320 by 256) it may overlap its trigger (2.4.11): the overlap is transient, and the tooltip is dismissable with Escape and hoverable (1.4.13), so nothing is lost. At 400% zoom it may cover content near the trigger: that is why it is hoverable and dismissable.
- RTL: placement and padding use logical properties and the tooltip is centred, so nothing flips.
Focus management#
- Initial focus: not moved, ever. The tooltip is never focused.
- Trap: no. Tab and Shift+Tab pass the trigger as for any control.
- Restore to: not applicable. Focus never leaves the trigger because of the tooltip: Escape hides the tooltip and focus stays.
- Never obscured by: at 320px wide and 640 high, and in the stories, the tooltip never covers its trigger (2.4.11), so the trigger's focus ring stays visible (2.4.7). In a viewport shorter than a long tooltip needs (320 by 256) it can overlap the trigger: that is transient, and Escape hides it and the pointer can leave. It is kept inside the viewport with some padding, and sits in the top layer, so no sticky header covers it.
WCAG success criteria#
- 1.4.13 Content on Hover or Focus (AA): dismissable (Escape), hoverable (the grace period and the pointer on the tooltip), persistent (no timeout, until hover or focus ends).
- 1.3.1 Info and Relationships (A), 4.1.2 Name, Role, Value (A):
role="tooltip",aria-describedby, and the trigger's own name. - 2.5.3 Label in Name (A): the tooltip starts with the trigger's name.
- 1.4.3 Contrast (Minimum) (AA), 1.4.1 Use of Color (A): the text, and no meaning in colour. The box's edge is a decorative hairline, so 1.4.11 Non-text Contrast (AA) asks nothing of it.
- 2.1.1 Keyboard (A), 2.1.2 No Keyboard Trap (A), 2.4.7 Focus Visible (AA), 2.4.11 Focus Not Obscured (Minimum) (AA): keyboard focus opens it, Escape hides it, and it covers its trigger only in a viewport too short for a long tooltip, where Escape hides it.
- 1.4.4 Resize Text (AA), 1.4.10 Reflow (AA), 1.4.12 Text Spacing (AA): limited to the viewport, wraps, no fixed height.
- 3.2.1 On Focus (A): opening a tooltip is not a change of context, and focus never moves.
Keyboard#
- Focus
- native
- Selection follows focus
- n/a
- Arrows wrap
- n/a
- Shortcuts
- none
The tooltip is never focused and never in the Tab order: the trigger owns the focus and its own keys. The tooltip adds no key of its own except Escape, and it takes none from the trigger.
| Key | Where | What happens |
|---|---|---|
| Tab | before the trigger | Moves focus to the trigger. Its tooltip opens at once Test: tooltip.test.tsx › Tab focuses the trigger and its tooltip opens at once |
| Shift+Tab | on the trigger | Moves focus to the previous focusable element. The tooltip closes Test: tooltip.test.tsx › Shift+Tab leaves the trigger and its tooltip closes |
| ArrowRight / ArrowLeft | on a toolbar control with a tooltip | The toolbar's own keys move focus to the next and previous control. Each control's tooltip opens at once and replaces the last, without waiting for the hover delay Test: tooltip.test.tsx › arrowing along a toolbar shows each tooltip at once |
| ArrowLeft / ArrowRight | on a toolbar control with a tooltip, right to left | The toolbar's arrows flip, and each tooltip still opens at once Test: tooltip.test.tsx › right to left: arrowing along a toolbar shows each tooltip at once |
| Enter / Space | on the trigger | The trigger's own: activates it. The tooltip stays open, and focus stays Test: tooltip.test.tsx › Enter and Space activate the trigger and the tooltip stays |
| Enter / Space | on a trigger that opens a popup | Opens its popup (a Popover, a Listbox). The tooltip closes, and stays closed while the popup is open Test: tooltip.test.tsx › a trigger that opens a popup closes its tooltip while the popup is open |
| Escape | the tooltip is open | Hides it. Focus stays on the trigger, and an open Popover underneath stays open (1.4.13 dismissable). A focused open Listbox or Combobox closes first and the tooltip needs a second Escape (Known issues) Test: tooltip.test.tsx › Escape hides the tooltip and focus stays, tooltip.test.tsx › Escape closes only the tooltip when a popover is open underneath |
| Escape | the tooltip was hidden with Escape, focus stays | It stays hidden until focus leaves the trigger and comes back Test: tooltip.test.tsx › after Escape the tooltip stays hidden until focus leaves and comes back |
| Escape | no tooltip is open | Not handled and not prevented: it passes on to whatever owns it (a Popover, the editor) Test: tooltip.test.tsx › Escape does nothing when no tooltip is open |
| Pointer hover | on the trigger | Opens the tooltip after the delay (500 ms by default). A pointer that passes over opens nothing Test: tooltip.test.tsx › hover opens the tooltip after the delay |
| Pointer hover | on the tooltip | The pointer can move from the trigger onto the tooltip, and the tooltip stays while it is there. Leaving both closes it after 100 ms (1.4.13 hoverable and persistent) Test: tooltip.test.tsx › the pointer can move onto the tooltip and it stays (hoverable) |
| Pointer hover | after Escape, the pointer still on the trigger | The tooltip stays hidden until the pointer leaves and comes back Test: tooltip.test.tsx › after Escape the tooltip stays hidden until the pointer leaves and comes back |
| Pointer press | on the trigger | Hides the tooltip until the pointer leaves and comes back. A click doesn't open it from focus Test: tooltip.test.tsx › reports why it opened and closed: focus, escape, blur, hover, pointer-leave and trigger-press, tooltip.test.tsx › a click does not open the tooltip from focus |
| Touch | on the trigger | Nothing: there is no tooltip on a touch screen, and no long press. The trigger's own name carries it Test: tooltip.test.tsx › a touch pointer opens no tooltip |
Tab never stops on the tooltip, and the arrow keys never land on it, also inside a Toolbar: it isn't focusable and has no role that a composite treats as an item.
API reference#
import { Tooltip, useTooltip } from '@kvirn-ui/react'Tooltip.Root
Renders no element. It owns the open state and the timing, and passes them to the parts inside it.
| Prop | Type | Default | Description |
|---|---|---|---|
open | boolean | – | Controlled: whether the tooltip is open. Pair it with onOpenChange. |
defaultOpen | boolean | false | Uncontrolled: whether the tooltip starts open. |
onOpenChange | (open: boolean, details: TooltipChangeDetails) => void | – | Called when the user opens or closes it. It only reports: with open set, you change open yourself. details.reason is hover, focus, escape, pointer-leave, blur or trigger-press. |
placement | Placement | 'top' | Where the tooltip goes when there is room: top, bottom, start or end, with -start, -center or -end. It flips when it does not fit. |
offset | number | 4 | The gap between the trigger and the tooltip, in pixels. |
padding | number | 8 | The space kept to the edge of the viewport, in pixels. |
delay | number | 500 | Milliseconds the pointer rests on the trigger before the tooltip opens. Keyboard focus opens it at once. |
closeDelay | number | 100 | Milliseconds after the pointer leaves before the tooltip closes. |
group | TooltipGroup | one group for the page | Where tooltips share their delay: once one has opened, the next opens at once. Make a separate group with createTooltipGroup() from @kvirn-ui/core. |
children | ReactNode | – | The Trigger and the Popup. Root renders no element. |
Tooltip.Trigger
Renders <button type="button">, or the component you give as, with its props set on the Trigger. It takes every attribute of that element and passes ref to it. The tooltip is placed against it.
| Prop | Type | Default | Description |
|---|---|---|---|
as | ElementType | 'button' | The control the tooltip belongs to, such as as={Button} aria-label="Search", with its props set on the Trigger. It must be focusable, forward its ref, spread its props on a DOM node and have a name of its own. |
| Class or attribute | Values | Meaning |
|---|---|---|
aria-describedby | an id, joined with yours | Points at the whole popup, or at Tooltip.Shortcut when there is one. Absent when the tooltip only repeats the name. |
Tooltip.Popup
Renders <div popover="manual"> with the role tooltip. It takes every attribute of a <div> and passes ref to it. It is always in the page and hidden while closed, so render it right after the trigger.
| Class or attribute | Values | Meaning |
|---|---|---|
kv-tooltip | always | The part class. |
popover | "manual" | Puts the tooltip in the top layer. The browser hides it while closed, and it never takes part in light dismiss. |
role | "tooltip" | The tooltip role. |
aria-hidden | "true" or absent | Set when the popup holds only Tooltip.Name: it adds nothing for assistive technology. |
data-open | present or absent | The tooltip is open. |
data-placement | a Placement, such as top | The side the tooltip is on now, after it flipped. |
data-detached | present or absent | The trigger is scrolled out of view. The tooltip is hidden until it comes back. |
--kv-popup-width, --kv-popup-max-height, --kv-anchor-width | lengths in px | Set on the popup: the room it has and the trigger’s width. |
--kv-popup-width-limit, --kv-popup-height-limit | lengths you set | Cap the width and height of the tooltip below the room that is left. |
Tooltip.Name
Renders <span>. It takes every attribute of a <span> and passes ref to it. It repeats the trigger’s name for sighted users and is hidden from screen readers, which read the trigger’s own name. A popup that holds only a Name adds nothing for a screen reader.
| Prop | Type | Default | Description |
|---|---|---|---|
as | 'span' | 'strong' | 'span' | Changes the element. Another tag warns once in development. |
| Class or attribute | Values | Meaning |
|---|---|---|
kv-tooltip-name | always | The part class. |
aria-hidden | "true" | The name is hidden from assistive technology, so it is heard once, from the trigger. |
Tooltip.Shortcut
Renders <span>. It takes every attribute of a <span> and passes ref to it.
| Prop | Type | Default | Description |
|---|---|---|---|
as | 'span' | 'small' | 'span' | Changes the element. Another tag warns once in development. |
| Class or attribute | Values | Meaning |
|---|---|---|
kv-tooltip-shortcut | always | The part class. |
id | generated | The trigger’s aria-describedby points at it. |
useTooltip
Options
| Prop | Type | Default | Description |
|---|---|---|---|
open | boolean | – | Controlled: whether the tooltip is open. Pair it with onOpenChange. |
defaultOpen | boolean | false | Uncontrolled: whether the tooltip starts open. |
onOpenChange | (open: boolean, details: TooltipChangeDetails) => void | – | Called when the user opens or closes it. It only reports: with open set, you change open yourself. details.reason is hover, focus, escape, pointer-leave, blur or trigger-press. |
placement | Placement | 'top' | Where the tooltip goes when there is room: top, bottom, start or end, with -start, -center or -end. It flips when it does not fit. |
offset | number | 4 | The gap between the trigger and the tooltip, in pixels. |
padding | number | 8 | The space kept to the edge of the viewport, in pixels. |
delay | number | 500 | Milliseconds the pointer rests on the trigger before the tooltip opens. Keyboard focus opens it at once. |
closeDelay | number | 100 | Milliseconds after the pointer leaves before the tooltip closes. |
group | TooltipGroup | one group for the page | Where tooltips share their delay: once one has opened, the next opens at once. Make a separate group with createTooltipGroup() from @kvirn-ui/core. |
description | 'popup' | 'shortcut' | 'none' | 'popup' | What the trigger’s aria-describedby points at: the whole popup, only the part with shortcutProps, or nothing (the whole popup is then aria-hidden). Tooltip.Root works this out from the parts it holds. |
Result
| Prop | Type | Default | Description |
|---|---|---|---|
isOpen | boolean | – | Whether the tooltip is open. |
placement | Placement | – | The placement in use. It differs from the one asked for when the tooltip flipped. |
triggerProps | TooltipTriggerPartProps | – | Spread on the control: ref, aria-describedby and the pointer and focus handlers. Join your own aria-describedby with it. |
popupProps | TooltipPopupPartProps | – | Spread on a <div>: popover="manual", role="tooltip", id, ref and the data attributes. |
nameProps | TooltipNamePartProps | – | Spread on the element that repeats the trigger’s name: aria-hidden. |
shortcutProps | TooltipShortcutPartProps | – | Spread on the element that adds information, such as the shortcut: its id. |
Known issues#
- In a viewport too short for a long tooltip, the tooltip may cover its trigger. It affects magnifier users at high zoom on a short viewport. A maximum width with wrapping keeps the tooltip narrow, so it grows in height instead and covers less. It is transient: Escape dismisses it and it is hoverable (1.4.13), so nothing is lost.
- Escape with a focused open Listbox or Combobox closes the listbox first. Those components handle Escape in their own key handler and call
preventDefault(), before the tooltip's document listener, which then ignores the key. One Escape closes the listbox and the tooltip stays; the next Escape hides it. The tested case is a Popover underneath. A Dialog is not covered by a test. - A pointer on another trigger closes this trigger's keyboard-focused tooltip, and it comes back when that tooltip closes while focus is still here. One tooltip of a group is open at a time. When the other tooltip closes (the pointer leaves it), the focused trigger's tooltip opens again (reason
focus), so a keyboard user's tooltip is never lost to a stray pointer. It also comes back when Escape hides the other tooltip, so with the pointer on another trigger it takes two Escapes to hide both. - A tooltip never takes an outside press. Its layer passes presses through, so a press elsewhere while a keyboard-focused tooltip is open reaches the Popover underneath in the same press. Escape is exact: one key closes the tooltip and the next closes the Popover.
- A trigger that scrolls out of view hides the tooltip rather than closing it. The popup is hidden and gets
data-detachedwhile the trigger is outside the viewport, and the tooltip returns with it. The tooltip's own state stays open. - The shared delay is page-wide. One group for the page, not one per provider. Give a
group(createTooltipGroup()) to scope it. role="tooltip"support varies between screen readers, which is why the trigger is complete without it and the shortcut is also inaria-keyshortcuts.
Information: Did you know?
If an issue here affects your service, list it in your accessibility statement with its workaround.
Testing#
The automated tests prove the keyboard behaviour, the names and states, that axe finds no violations in every story and theme, and, for the components they cover, that the stories hold up in forced colours, reduced motion, text spacing and a 320 pixel width. An Automated row passes on these tests alone. A Core or Release row passes only when an automated agent check and a person on the real assistive technology have both checked it. "agent-verified" means automated tests in the repository (with a virtual screen reader for the screen reader rows), not the real assistive technology.
| AT + browser + OS | Agent check | Human check | Result | Notes |
|---|---|---|---|---|
| Automated (re-runnable tests) | ||||
| axe, WCAG 2.2 A and AA, every story, 4 themes | pass | n/a | pass | tooltip.stories.tsx, every story, 4 themes |
| Markup and ARIA (roles, names, ids, states) | pass | n/a | pass | tooltip.test.tsx › closed: the popup is in the DOM, hidden, a role="tooltip" in the top layer, and the trigger is described by its shortcut; expectNoA11yViolations |
| Keyboard contract rows (Vitest browser) | pass | n/a | pass | 14 rows, each names a test (tooltip.test.tsx › Tab focuses the trigger and its tooltip opens at once) |
| Focus order and management | pass | n/a | pass | tooltip.test.tsx asserts focus (toHaveFocus); first rule: Tab focuses the trigger and its tooltip opens at once |
| Display modes (forced colours, 320px reflow, text spacing, reduced motion) | pass | n/a | pass | the four sweep projects (storybook-forced-colors, -reduced-motion, -reflow, -text-spacing), run in CI |
| Core (required for beta) | ||||
| NVDA + Chrome + Windows | pending | pending | pending | |
| VoiceOver + Safari + iOS | pending | pending | pending | |
| Release (before 1.0 and each minor) | ||||
| JAWS + Chrome + Windows | pending | pending | pending | |
| TalkBack + Chrome + Android | pending | pending | pending | |
| VoiceOver + Safari + macOS | pending | pending | pending |
Also pending, by hand: whether NVDA, JAWS and VoiceOver read an icon-only button's name once and its shortcut once (the trigger has aria-keyshortcuts and the description), whether a screen reader reads the hidden-from-AT name again in browse mode while the tooltip is open, and whether a magnifier user at 400% can reach the tooltip by moving the pointer onto it.
What to check#
With a screen reader and the keyboard, try:
- Tab to an icon-only button: the tooltip shows at once, and the name is read once.
- With a shortcut: the name is read once, then the shortcut once after it.
- Escape hides the tooltip, focus stays, and the page behind does not react.
- Hover for half a second shows the tooltip, and moving onto it keeps it.
- At 400% zoom the tooltip can be dismissed and never hides the button for good.
- On touch, a tap shows no tooltip, and the button's name is enough.