ActivityRail
Use the rail for a short list of peer destinations. Give the navigation landmark an aria-label, supply a stable id, label and decorative icon per item, and set selectedId when navigation completes.
Live example
Open playground ↗App.tsx
import { useState } from 'react'
import '@ancrel/tokens/css'
import '@ancrel/workspace/styles.css'
import { ActivityRail } from '@ancrel/workspace'
export default function App() {
const [page, setPage] = useState('overview')
return <ActivityRail aria-label="Project pages" selectedId={page} onSelect={setPage}
items={[
{ id: 'overview', label: 'Overview', icon: '▦' },
{ id: 'updates', label: 'Updates', icon: '◷', badge: 121 },
{ id: 'saved', label: 'Saved', icon: '☆', badge: 'dot' },
]} />
}
Expected behavior
Tab enters on Overview. Arrow Down focuses Updates. Its badge displays 99+ and its accessible name includes 121. Enter selects Updates. Saved has a dot and announces “Saved (new)”.
Tab enters the item list once. Up and Down wrap through enabled destinations. Home and End jump to either end. Enter or Space activates the focused destination. The current page carries aria-current="page"; moving focus alone preserves selection. The footer accepts independently focusable controls.
An item with href renders a link. For a router, pass renderLink and forward its props, including children and keyboard handler, to the focusable link. Setting showLabels={false} hides the visible labels while preserving accessible names. A numeric badge displays at most 99+ and announces the exact count. A dot adds “new” to the name. Return the complete localized name from formatBadgeLabel.
The width comes from --ac-comp-rail-width. Labels use --ac-sys-type-meta-size. Import @ancrel/tokens/css and @ancrel/workspace/styles.css in the application entry point.
Props
| Prop | Type | Required | Default |
|---|---|---|---|
aria-label | string | Yes | — |
footer | ReactNode | No | — |
formatBadgeLabel | ((item: ActivityRailItem) => string) | undefined | No | — |
items | readonly ActivityRailItem[] | Yes | — |
key | React.Key | null | undefined | No | — |
onSelect | ((id: string, event: React.MouseEvent | React.KeyboardEvent) => void) | undefined | No | — |
ref | React.Ref<HTMLElement> | undefined | No | — |
renderLink | ((props: { href: string; className: string; children: React.ReactNode; "aria-current"?: "page"; tabIndex: number; onKeyDown: React.KeyboardEventHandler; }) => React.ReactElement) | undefined | No | — |
selectedId | string | null | No | — |
showLabels | boolean | No | — |
State matrix
| State | Theme / density |
|---|---|
| default | dark/compact, dark/comfortable, light/compact, light/comfortable |
| hover | dark/compact, dark/comfortable, light/compact, light/comfortable |
| focus-visible | dark/compact, dark/comfortable, light/compact, light/comfortable |
| disabled | dark/compact, dark/comfortable, light/compact, light/comfortable |
Constraints
- Provide a navigation label and a stable unique id for each item.
- Forward every renderLink prop to the focusable link.
Anti-patterns
- Putting interactive elements inside item icons.
- Using the capped visual count as the accessible name.