Skip to content

Signal

Components

Menu

A popover behind a 44pt toggle for secondary header tools on phones; --inline shows the items in place.

Live example

Rendered with the real classes from /site/chitransit.css, light (left) and dark (right).

Install
.ct-menu.is-open · .ct-menu-toggle · .ct-menu-panel · .ct-menu-item
Install
.ct-menu--inline

Code

<div class="sd-menu-demo"><div class="ct-menu is-open"><button class="ct-menu-toggle" type="button" aria-label="Theme and links" aria-expanded="true" aria-controls="demo-menu-panel"><svg aria-hidden="true"><use href="#i-more"/></svg></button><div class="ct-menu-panel" id="demo-menu-panel"><div class="ct-segmented" role="radiogroup" aria-label="Theme"><button role="radio" aria-checked="true" tabindex="0">System</button><button role="radio" aria-checked="false" tabindex="-1">Light</button><button role="radio" aria-checked="false" tabindex="-1">Dark</button></div><a class="ct-menu-item" href="/getting-started/install"><svg aria-hidden="true"><use href="#i-check"/></svg><span class="ct-menu-item-label">Install</span></a></div></div></div>
<div class="ct-menu ct-menu--inline"><button class="ct-menu-toggle" type="button" aria-label="Theme and links" aria-expanded="false"><svg aria-hidden="true"><use href="#i-more"/></svg></button><div class="ct-menu-panel"><div class="ct-segmented" role="radiogroup" aria-label="Theme"><button role="radio" aria-checked="true" tabindex="0">System</button><button role="radio" aria-checked="false" tabindex="-1">Light</button><button role="radio" aria-checked="false" tabindex="-1">Dark</button></div><a class="ct-menu-item" href="/getting-started/install"><svg aria-hidden="true"><use href="#i-check"/></svg><span class="ct-menu-item-label">Install</span></a></div></div>

Tokens

From tokens/components.tokens.json. Override one instance by setting the property without the ct- prefix.

Custom propertyValueAliasResolves to
--ct-menu-inline-gapvar(--space-16){space.s16}16 pt
--ct-menu-item-background-hovervar(--card){colors.card}#EDEEF1 #1D232D
--ct-menu-item-check-colorvar(--accent){colors.accent}#0B4EA2 #92B8F5
--ct-menu-item-check-sizevar(--size-metadata-glyph){size.metadataGlyph}16 pt
--ct-menu-item-colorvar(--ink){colors.ink}#101A2E #EEF1F6
--ct-menu-item-color-hovervar(--ink){colors.ink}#101A2E #EEF1F6
--ct-menu-item-font-sizevar(--fs-body){type.body}16
--ct-menu-item-font-weightvar(--weight-medium){weight.medium}500
--ct-menu-item-gapvar(--space-8){space.s8}8 pt
--ct-menu-item-heightvar(--size-minimum-tap-target){size.minimumTapTarget}44 pt
--ct-menu-item-indentvar(--space-32){space.s32}32 pt
--ct-menu-item-padding-xvar(--space-12){space.s12}12 pt
--ct-menu-item-radiusvar(--radius-segment){radius.segment}8 pt
--ct-menu-item-swatch-sizevar(--size-menu-swatch){size.menuSwatch}12 pt
--ct-menu-panel-backgroundvar(--paper){colors.paper}#FFFFFF #0F141C
--ct-menu-panel-bordervar(--line){colors.line}#DADDE3 #263041
--ct-menu-panel-gapvar(--space-8){space.s8}8 pt
--ct-menu-panel-offsetvar(--space-6){space.s6}6 pt
--ct-menu-panel-paddingvar(--space-12){space.s12}12 pt
--ct-menu-panel-radiusvar(--r-modal){radius.dialog}20 pt
--ct-menu-panel-shadowvar(--shadow-fab){shadows.floating}
--ct-menu-panel-width300px
--ct-menu-panel-z-indexvar(--z-menu){zIndex.menu}1001 index
--ct-menu-toggle-background-activevar(--card){colors.card}#EDEEF1 #1D232D
--ct-menu-toggle-background-hovervar(--card){colors.card}#EDEEF1 #1D232D
--ct-menu-toggle-color-activevar(--ink){colors.ink}#101A2E #EEF1F6
--ct-menu-toggle-colorvar(--muted){colors.muted}#5B6472 #B0BACA
--ct-menu-toggle-color-hovervar(--ink){colors.ink}#101A2E #EEF1F6
--ct-menu-toggle-glyph-sizevar(--size-control-glyph){size.controlGlyph}22 pt
--ct-menu-toggle-sizevar(--size-minimum-tap-target){size.minimumTapTarget}44 pt

Script

Load @chitransit/signal/menu.js once per page (the docs serve it at /site/menu.js). It handles every .ct-menu, including ones added later: a click on .ct-menu-toggle opens or closes the panel and keeps aria-expanded in sync; Escape closes it and returns focus to the toggle; a click outside closes it. Give the menu data-collapse="(max-width:760px)" to make it a popover only while the query matches (it shows the items in place with .ct-menu--inline otherwise), and call ChiTransitMenu.init(root) after rendering such a menu. ChiTransitMenu.setOpen(menu, open) and ChiTransitMenu.close() drive it from code.

<script src="/vendor/signal/menu.js" defer></script>
<div class="ct-menu" data-collapse="(max-width:760px)">
  <button class="ct-menu-toggle" type="button" aria-label="Theme and links" aria-expanded="false" aria-controls="tools">…</button>
  <div class="ct-menu-panel" id="tools">…</div>
</div>

Variants

The default .ct-menu is a popover: a .ct-menu-toggle and a .ct-menu-panel, open while the menu has .is-open. --inline shows the items in place with no toggle; --leading opens the panel beside the toggle's leading side. .ct-menu-item--indent nests a row. Nothing else exists.

  • Secondary tools behind one toggle on a phone: the default.
  • The same items in place on a wide screen: --inline, or data-collapse with menu.js to switch at a breakpoint.
  • A menu beside a control stack (the map layers): --leading.
<!-- Do -->
<div class="ct-menu" data-collapse="(max-width:760px)">
  <button class="ct-menu-toggle" type="button" aria-label="Theme and links" aria-expanded="false" aria-controls="tools">…</button>
  <div class="ct-menu-panel" id="tools">…</div>
</div>
<!-- Don't: a menu inside a menu -->
<div class="ct-menu-panel" id="tools">
  <div class="ct-menu">…</div>
</div>

Usage

Do

  • Use a menu to move secondary header tools (theme switch, links) behind one toggle on phones, so the primary navigation keeps full-size targets.
  • Use data-collapse with menu.js to show the same items in place on wide screens.
  • A segmented control in the popover takes the touch size and spans the panel; in --inline it keeps its normal size.

Don't

  • Don't hide primary navigation in a menu.
  • Don't nest menus.

Accessibility

  • The toggle has an aria-label, aria-expanded and aria-controls naming the panel.
  • menu.js moves focus to the first item when the popover opens; ArrowUp and ArrowDown step between items and Home and End jump to the ends.
  • menu.js closes the menu on Escape, on a click outside and when Tab moves focus out of it; Escape returns focus to the toggle.
  • Items are links or buttons with visible labels.