Components
Tooltip
A short hint on hover or focus: add data-tooltip to any element with .ct-tooltip.
Live example
Rendered with the real classes from /site/chitransit.css, light (left) and dark (right).
.ct-tooltip + .ct-tooltip-textCode
<button class="ct-button ct-button--sm ct-tooltip is-visible" aria-describedby="tip-updated">Refresh<span class="ct-tooltip-text" id="tip-updated" aria-hidden="true">Updated 15 s ago</span></button>
Tokens
From tokens/components.tokens.json. Override one instance by setting the property without the ct- prefix.
| Custom property | Value | Alias | Resolves to |
|---|---|---|---|
--ct-tooltip-background | var(--live-bg) | {colors.liveBg} | #101A2E #EEF1F6 |
--ct-tooltip-color | var(--live-ink) | {colors.liveInk} | #FFFFFF #0F141C |
--ct-tooltip-delay | .2s | ||
--ct-tooltip-duration | var(--motion-control-duration) | {motion.controlDuration} | .15 s |
--ct-tooltip-font-size | var(--fs-cap) | {type.cap} | 12 |
--ct-tooltip-font-weight | var(--weight-semibold) | {weight.semibold} | 600 |
--ct-tooltip-max-width | var(--size-tooltip-maximum-width) | {size.tooltipMaximumWidth} | 240 pt |
--ct-tooltip-offset | var(--space-6) | {space.s6} | 6 pt |
--ct-tooltip-padding-x | var(--space-8) | {space.s8} | 8 pt |
--ct-tooltip-padding-y | var(--space-4) | {space.s4} | 4 pt |
--ct-tooltip-radius | var(--radius-chip) | {radius.chip} | 6 pt |
--ct-tooltip-z-index | var(--z-tooltip) | {zIndex.tooltip} | 1050 index |
Variants
.ct-tooltip shows its hint above the element; --below places it under. The hint is a .ct-tooltip-text child (announced) or data-tooltip (not announced). Nothing else exists.
<!-- Do -->
<button class="ct-button ct-button--sm ct-tooltip" aria-describedby="tip-updated">Refresh<span class="ct-tooltip-text" id="tip-updated" aria-hidden="true">Updated 15 s ago</span></button>
<!-- Don't: a tooltip as the only name of a control -->
<button class="ct-icon-button ct-tooltip" data-tooltip="Favorite"><svg aria-hidden="true">…</svg></button>
Usage
Do
- Use a tooltip for a short hint on hover or focus, such as when data was updated.
Don't
- Don't hide essential information in a tooltip; touch users may never see it.
Accessibility
- Put the hint in a child
<span class="ct-tooltip-text" id="…" aria-hidden="true">and point the element'saria-describedbyat it, so it is announced as a description and stays out of the name.data-tooltipstill works but is not announced. - Load
@chitransit/signal/tooltip.js: Escape hides an open hint without moving the pointer or focus. - Hover waits
tooltip.delay; focus shows the hint at once. The pointer can move onto the hint. - Repeat anything essential in the accessible name.