AncrelDocumentationv0.3.0

Search documentation

    Documentation / frontend

    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

    PropTypeRequiredDefault
    aria-labelstringYes—
    footerReactNodeNo—
    formatBadgeLabel((item: ActivityRailItem) => string) | undefinedNo—
    itemsreadonly ActivityRailItem[]Yes—
    keyReact.Key | null | undefinedNo—
    onSelect((id: string, event: React.MouseEvent | React.KeyboardEvent) => void) | undefinedNo—
    refReact.Ref<HTMLElement> | undefinedNo—
    renderLink((props: { href: string; className: string; children: React.ReactNode; "aria-current"?: "page"; tabIndex: number; onKeyDown: React.KeyboardEventHandler; }) => React.ReactElement) | undefinedNo—
    selectedIdstring | nullNo—
    showLabelsbooleanNo—

    State matrix

    StateTheme / density
    defaultdark/compact, dark/comfortable, light/compact, light/comfortable
    hoverdark/compact, dark/comfortable, light/compact, light/comfortable
    focus-visibledark/compact, dark/comfortable, light/compact, light/comfortable
    disableddark/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.