Tooltip
A short label that appears when its trigger is hovered or focused. It stands centred above its control, two pixels clear, and never leaves the window: near an edge it moves to stand four pixels inside it, and with no room above it stands below (or above, with placement="bottom" and no room below).
Design examples
Section titled “Design examples”Focus or hover the compact controls to read their full action names.
<section class="specimen">
<ds-row class="line" ><ds-tooltip text="Add to selected works"><ds-button secondary label="Add to selected works"><span class="mark"><ds-icon type="star" size="large" aria-hidden="true"></ds-icon></span></ds-button></ds-tooltip><ds-tooltip text="Download original"><ds-button secondary label="Download original"><span class="mark"><ds-icon type="download" size="large" aria-hidden="true"></ds-icon></span></ds-button></ds-tooltip><ds-tooltip text="Move to archive"><ds-button secondary label="Move to archive"><span class="mark"><ds-icon type="archive" size="large" aria-hidden="true"></ds-icon></span></ds-button></ds-tooltip></ds-row>
</section>
<style>
.specimen { width: 100%; min-width: 0; --cell: calc(20px * var(--sf, 1)); }
.specimen .line { width: 100%; }
.specimen .grow { flex: 1; min-width: 0; }
.specimen .muted { color: var(--ds-text-color-muted); }
.specimen .mono { --ds-typeface-regular: var(--ds-typeface-mono); font-variant-numeric: tabular-nums; }
.specimen .value { width: calc(4 * var(--cell)); text-align: right; }
.specimen .mark { display: inline-flex; align-items: flex-end; width: var(--cell); height: var(--ds-control-height); flex: 0 0 var(--cell); }
.specimen .columns { display: flex; flex-wrap: wrap; gap: var(--cell); }
.specimen .columns > * { min-width: 0; }
.specimen fieldset { border: 0; padding: 0; margin: 0; }
.specimen legend { padding: 0; }
.specimen label { display: flex; align-items: flex-end; gap: calc(var(--cell) / 2); min-height: var(--cell); }
.specimen ds-panel { height: calc(10 * var(--cell)); }
</style> Try it
Section titled “Try it”The label starts visible. Hover over the button, or focus it with Tab to try it.
<ds-tooltip text="Save your changes">
<ds-button secondary>Hover or focus me</ds-button>
</ds-tooltip> Hover or focus to see the fallback when the key has no translation.
<ds-tooltip text="actions.save.help" default-value="Keep your changes">
<ds-button primary>Save</ds-button>
</ds-tooltip> When to use it
Section titled “When to use it”Use a tooltip to clarify a compact control. Keep essential instructions visible on the page: someone on a touch screen may never hover. Put a focusable button or link inside the wrapper so keyboard users can reveal the label too.
Attributes
Section titled “Attributes”| Attribute | Type | Default | What it does |
|---|---|---|---|
text | string | Empty | A translation key or literal label. |
default-value | string | Empty | Fallback when the key has no translation. |
Behaviour
Section titled “Behaviour”The label appears above the trigger on hover or focus and disappears on mouse leave or focus leaving the trigger. position is not a supported attribute: the component always places its label above the trigger.
Many tooltips on one page
Section titled “Many tooltips on one page”For a collection of controls, the shared tooltip module also supports data-tooltip="Save changes". Import DS1/0-face/tooltips.ts once; it draws a shared label for those elements, including marked elements inside a component’s open shadow root, as the Sidebar marks its cut-short labels. Mark only what the label adds to: a cut-short or icon-only control, never every row.
The shared label:
- shows at once on hover with a mouse or pen;
- shows on focus only when the focus is the keyboard’s (
:focus-visible), so a menu that moves focus into its first row on a press does not raise one; - follows its element’s
data-tooltip(anddata-tooltip-colour) while it shows, so a play button that turns into a pause button says so, and goes when the text does; - on touch, shows from a long press (half a second), and the click that releasing the finger makes is held back; an element marked
data-tooltip-pressshows it from a tap as well, and still gets its click. A touch label goes at the next touch or after two seconds, and a finger that moves is scrolling, not pressing.
From code, showTooltip(element) shows an element’s label as a press would, until hideTooltip(); showTooltip(element, { duration: 2000 }) hides it after that many milliseconds.
<button data-tooltip="Size 40" data-tooltip-press>40</button>import { showTooltip, hideTooltip } from './ds1/0-face/tooltips';
showTooltip(button, { duration: 2000 });Sync 1’s root export copies the module with "modules": ["tooltips"].
Related components
Section titled “Related components”Button provides a focusable trigger. Icon supplies a compact drawing. Languages explains translation keys.