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).
.ct-menu.is-open · .ct-menu-toggle · .ct-menu-panel · .ct-menu-item.ct-menu--inlineCode
<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 property | Value | Alias | Resolves to |
|---|---|---|---|
--ct-menu-inline-gap | var(--space-16) | {space.s16} | 16 pt |
--ct-menu-item-background-hover | var(--card) | {colors.card} | #EDEEF1 #1D232D |
--ct-menu-item-check-color | var(--accent) | {colors.accent} | #0B4EA2 #92B8F5 |
--ct-menu-item-check-size | var(--size-metadata-glyph) | {size.metadataGlyph} | 16 pt |
--ct-menu-item-color | var(--ink) | {colors.ink} | #101A2E #EEF1F6 |
--ct-menu-item-color-hover | var(--ink) | {colors.ink} | #101A2E #EEF1F6 |
--ct-menu-item-font-size | var(--fs-body) | {type.body} | 16 |
--ct-menu-item-font-weight | var(--weight-medium) | {weight.medium} | 500 |
--ct-menu-item-gap | var(--space-8) | {space.s8} | 8 pt |
--ct-menu-item-height | var(--size-minimum-tap-target) | {size.minimumTapTarget} | 44 pt |
--ct-menu-item-indent | var(--space-32) | {space.s32} | 32 pt |
--ct-menu-item-padding-x | var(--space-12) | {space.s12} | 12 pt |
--ct-menu-item-radius | var(--radius-segment) | {radius.segment} | 8 pt |
--ct-menu-item-swatch-size | var(--size-menu-swatch) | {size.menuSwatch} | 12 pt |
--ct-menu-panel-background | var(--paper) | {colors.paper} | #FFFFFF #0F141C |
--ct-menu-panel-border | var(--line) | {colors.line} | #DADDE3 #263041 |
--ct-menu-panel-gap | var(--space-8) | {space.s8} | 8 pt |
--ct-menu-panel-offset | var(--space-6) | {space.s6} | 6 pt |
--ct-menu-panel-padding | var(--space-12) | {space.s12} | 12 pt |
--ct-menu-panel-radius | var(--r-modal) | {radius.dialog} | 20 pt |
--ct-menu-panel-shadow | var(--shadow-fab) | {shadows.floating} | |
--ct-menu-panel-width | 300px | ||
--ct-menu-panel-z-index | var(--z-menu) | {zIndex.menu} | 1001 index |
--ct-menu-toggle-background-active | var(--card) | {colors.card} | #EDEEF1 #1D232D |
--ct-menu-toggle-background-hover | var(--card) | {colors.card} | #EDEEF1 #1D232D |
--ct-menu-toggle-color-active | var(--ink) | {colors.ink} | #101A2E #EEF1F6 |
--ct-menu-toggle-color | var(--muted) | {colors.muted} | #5B6472 #B0BACA |
--ct-menu-toggle-color-hover | var(--ink) | {colors.ink} | #101A2E #EEF1F6 |
--ct-menu-toggle-glyph-size | var(--size-control-glyph) | {size.controlGlyph} | 22 pt |
--ct-menu-toggle-size | var(--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, ordata-collapsewith 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-collapsewith 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
--inlineit 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-expandedandaria-controlsnaming 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.