Skip to content

Signal

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-text

Code

<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 propertyValueAliasResolves to
--ct-tooltip-backgroundvar(--live-bg){colors.liveBg}#101A2E #EEF1F6
--ct-tooltip-colorvar(--live-ink){colors.liveInk}#FFFFFF #0F141C
--ct-tooltip-delay.2s
--ct-tooltip-durationvar(--motion-control-duration){motion.controlDuration}.15 s
--ct-tooltip-font-sizevar(--fs-cap){type.cap}12
--ct-tooltip-font-weightvar(--weight-semibold){weight.semibold}600
--ct-tooltip-max-widthvar(--size-tooltip-maximum-width){size.tooltipMaximumWidth}240 pt
--ct-tooltip-offsetvar(--space-6){space.s6}6 pt
--ct-tooltip-padding-xvar(--space-8){space.s8}8 pt
--ct-tooltip-padding-yvar(--space-4){space.s4}4 pt
--ct-tooltip-radiusvar(--radius-chip){radius.chip}6 pt
--ct-tooltip-z-indexvar(--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's aria-describedby at it, so it is announced as a description and stays out of the name. data-tooltip still 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.