Tooltip
A short label shown next to a control on hover and keyboard focus.
mq-tooltip is web patient's Tooltip as a design-system primitive. It ships
from @mediquo/ui as a custom element and as a React component.
Install
// Custom element — the import registers <mq-tooltip>
import "@mediquo/ui/components/tooltip";// React
import { Tooltip } from "@mediquo/ui/react/tooltip";Usage
The first child is the trigger. The element with slot="content" is the
bubble's text.
<Tooltip side="right">
<button type="button" aria-label="Ajustes">
<SettingsIcon aria-hidden="true" />
</button>
<span slot="content">Ajustes</span>
</Tooltip>side is top (the default), right, bottom or left, and align is
start, center (the default) or end. If the bubble does not fit on its
side but fits on the opposite one, it flips there. It also slides along the
edge to stay inside the viewport, and the arrow keeps pointing at the trigger.
side-offset adds a gap in pixels.
It opens when the pointer rests on the trigger (after delay milliseconds,
0 by default) or when the trigger gets keyboard focus. It closes when the
pointer leaves, focus leaves, the trigger is pressed, or the user presses
Escape. open shows it from code, and onopenchange reports every change.
disabled keeps it closed, for example while a sidebar is expanded and its
labels are already visible.
Accessibility
- The trigger's
aria-describedbypoints at the content element, which gets an id if it has none. Ids the trigger already lists are kept. - The trigger has to be the focusable element itself, such as a native
<button>or<a>.aria-describedbycannot reach a control inside another element's shadow root, so withmq-buttonas the trigger the tooltip is only visual. In that case, make sure the button's ownlabelalready says it. - Pointer users can move from the trigger into the bubble without it closing, and Escape dismisses it without moving focus (WCAG 1.4.13).
- Hovering with touch does nothing. A tap focuses or presses the trigger instead.
- The bubble is a popover in the top layer, so
overflow: hiddenand stacking contexts around the trigger cannot clip it. - Under
prefers-reduced-motion: reduceit appears and disappears without animating. Forced-colours mode draws a border around it.
Styling
The component uses --mq-* tokens with literal fallbacks.
--mq-tooltip-background, --mq-tooltip-color, --mq-tooltip-radius and
--mq-tooltip-max-width override the bubble, and part="content" and
part="arrow" reach it and its arrow.