Tooltip
catnip-tooltip opens on focus as well as hover, closes on Escape without closing a surrounding Dialog or Drawer, supports Enter and Space in click mode, and describes its default icon trigger while visible. With a custom anchor, you provide the focusable control and its description; keep the content short and non-interactive.
Keyboard
| Key | Behaviour |
|---|---|
| Tab | Focuses the trigger. With trigger="hover", moving focus to the trigger shows the tooltip (same as hover for pointer users) while showOnFocus is on (the default). |
| Enter / Space | With trigger="click", activates the trigger. |
| Escape | Closes the tooltip, in both trigger modes, and focus stays where it is. It opens again the next time the trigger is hovered or focused. |
- Default icon trigger: the anchor wrapper is
tabindex="0"so keyboard users can focus it. Withdisabled, the default icon trigger is not keyboard-focusable. - Custom
anchorslot: no wrappertabindex, so focus stays on the control you slot. - With
trigger="click", an outside click also closes the tooltip. - Escape inside Dialog, Drawer and popups: while the tooltip is visible, it takes Escape for itself. The key isn't passed on, so the first Escape closes only the tooltip and a surrounding Dialog, Drawer or open popup stays open; the next Escape reaches it. While the tooltip is hidden, or open but not on screen (for example inside a hidden tab panel), Escape passes through untouched. Escape that ends an IME composition is left to the input method.
Screen readers
- With the default icon trigger, the trigger is described by the tooltip (
aria-describedby) only while it's visible. - With a custom anchor, that description can't reach your control: the tooltip bubble is inside the tooltip's shadow root, which your control's ID references can't enter. Your content stays in your tree, though, so wrap it in an element with an
idand point your control'saria-describedbyat that element. Catnip's field labels do this forinfo. - The content stays in the page while the tooltip is hidden: the bubble is hidden with
display: none, not removed, and your content stays slotted into it. Your control therefore has its description before the tooltip first opens, while it's open and after Escape closes it. Hidden content isn't read on its own; it's only read as the description. - With
trigger="click",aria-expandedreflects open state. disabledsetsaria-disabled="true".
A custom anchor described by the tooltip content:
html
<catnip-tooltip>
<button type="button" slot="anchor" aria-describedby="delete-hint">Delete</button>
<span id="delete-hint">Removes the file for everyone</span>
</catnip-tooltip>What you own
- Custom anchor: Put focus on a native control (
<button>,<a href>, etc.) to avoid nested focusables and duplicate tab stops. Give it an accessible name, and connect the tooltip text witharia-describedbyas described above. - Controlled
open: while the tooltip is open, Escape emitsopen-changewithfalseand isn't passed on. Close the tooltip in your handler. A tooltip you keep open keeps taking Escape, so a surrounding Dialog or Drawer can't be closed with Escape until the tooltip closes; its close button and footer actions still work. - Content: This component targets short, non-interactive hints. Rich or interactive content inside the tooltip is better served by a dialog or popover pattern.