# Section rail

A narrow rail beside a long view: its sections, where the reader is, and a jump to each.

Live variants: https://design.arcadia.is/components/section-rail

```tsx
import { SectionRail, useSectionSpy } from "@arcadia/ui";
```

Jump to a heading and watch the rail mark your place.

```tsx
import { useRef } from "react";
import { ScrollArea, useSectionSpy, SectionRail } from "@arcadia/ui";

function Demo() {
  const view = useRef<HTMLDivElement>(null);
  const spy = useSectionSpy({ ids: GUIDE.map((g) => g.id), scroller: view });
  return (
    <div {...sx("rail-demo", page.demo)}>
      <div {...sx("rail-demo-scroller", page.scroller)}>
        <ScrollArea label="Guide" viewportRef={view} rootStyle={page.scrollFill}>
          <div {...sx("rail-demo-view", page.view)}>
            {GUIDE.map((g) => (
              <div key={g.id}>
                <h3 id={g.id} data-toc-skip {...sx("rail-demo-heading", page.heading)}>{g.label}</h3>
                <p {...stylex.props(page.guideText)}>{g.text}</p>
              </div>
            ))}
          </div>
        </ScrollArea>
      </div>
      <SectionRail
        label="On this page"
        items={GUIDE.map(({ id, label, level }) => ({ id, label, level }))}
        current={spy.current}
        onJump={spy.jump}
      />
    </div>
  );
}
```

## Accessibility

A navigation landmark named by its label. One Tab stop: the row you are reading, or the first. Up and Down move between rows, Home and End to the ends; Enter jumps and moves focus to the section. The row you are reading is `aria-current="location"`.

The reader's place is never announced.

Under forced colours the rail is the system's grey and the thumb its highlight. Every row is a link, so the rail works with no script and a row opens in a new tab with a modifier.

## API reference

### SectionRail

- `items` (`readonly SectionRailItem[]`, required): The view's sections, in order. Fewer than two draw nothing.
- `label` (`string`, required): The rail's name, shown over it and heard as the navigation's name: "On this page".
- `showLabel` (`boolean`, default `true`): `false`: the name is heard only (a rail folded under a lead that already says it).
- `current` (`string | null`, required): The id of the section the reader is in now, from `useSectionSpy`; `null` when none is known.
- `onJump` (`(id: string, from: SectionRailFrom) => void`): A row was chosen: jump there (`useSectionSpy`'s `jump`). Left out, every row is a plain link to `#id`.
- `rail` (`boolean`, default `true`): `false`: no line and no thumb; the current row is told by its ink alone (a rail folded under a lead, a page with no script).
- `rootStyle` (`RootStyle`): Typed StyleX override: layout only (where it stands, sticky, its height).

Rest props go to `<nav>` props.
