Search documentation

Search pages, components, blocks, styles and colours.

Get started
Skip to content

Preview Rail

PreviousNext

A rail of thin ticks, one per section, that swell around the pointer with a card naming the section it's on.

Move the pointer along the rail: the ticks swell around the one it's on, like a dock, and a card beside the rail names that section. The card glides from tick to tick. With the pointer away, the swell rests on the current section, so the rail still shows where the reader is. On a touch screen a finger scrubs: a press lights the tick under it, a drag moves the light, and lifting on the rail follows the lit section.

Preview Rail is part of the Fabricator style. It's built on HTML, so the same component ships for every base.

Installation

bunx --bun fabricator-ui@latest add preview-rail

Usage

import { PreviewRail } from "@/components/ui/preview-rail"
<PreviewRail
  aria-label="On this page"
  defaultValue="installation"
  items={[
    { value: "overview", label: "Overview", href: "#overview" },
    {
      value: "installation",
      label: "Installation",
      description: "Add the CLI and set up your first project.",
      href: "#installation",
    },
    { value: "usage", label: "Usage", href: "#usage" },
  ]}
/>

Use it for a page's sections or a sequence of places, such as chapters, months or steps, where the rail is compact and the names can wait for the pointer. When people need to read every name at once, use Tabs or a Sidebar instead. An item with an href is a link; without one it's a button, and onValueChange says which was chosen.

Composition

Preview Rail is one component. Its parts carry a data-slot for styling from outside:

PreviewRail                      data-slot="preview-rail"
├── div (the rail)               data-slot="preview-rail-list"
│   └── a | button (one a tick)  data-slot="preview-rail-item" data-current data-lit
│       └── span                 data-slot="preview-rail-tick"
└── div (the card's track)       data-slot="preview-rail-preview"
    └── div                      data-slot="preview-rail-card" data-open | data-closed
        └── div                  data-slot="preview-rail-content"
            ├── p                data-slot="preview-rail-title"
            └── p                data-slot="preview-rail-description"

Examples

Horizontal

orientation="horizontal" lays the ticks in a row, with the card above them.

Controlled

Pass value and onValueChange to keep the current item in your state, such as the section scrolled into view. side="start" puts the card before the rail, here on its left. A disabled item dims and is skipped.

Showing Inbox

Custom card

renderPreview draws the card's content for an item, here a chapter's time above its name.

Motion

The ticks swell on the move timing: the lit one to its full length, the next ones to three quarters and three fifths, and the rest stay short. The card grows from the rail on the popup motion, glides between ticks on the move timing, and its content fades in as it arrives. Near the ends of the rail it stops at the rail's edge rather than running past it. It closes quicker than it opens.

Everything follows the speed setting. Reduce Motion keeps the fades and drops the swell's travel, the glide and the growth.

API Reference

PreviewRail

PropTypeDefault
itemsPreviewRailItem[]Required
orientation"vertical" | "horizontal""vertical"
side"start" | "end""end" when vertical, "start" when horizontal
valuestring(none)
defaultValuestringThe first enabled item
onValueChange(value: string) => void(none)
renderPreview(item: PreviewRailItem) => ReactNodeThe item's label and description
aria-labelstring"Section navigation"

The root is a nav and takes its props and ref. side places the card: end after a vertical rail (on its right) or below a horizontal one, start before a vertical rail or above a horizontal one.

PreviewRailItem

FieldTypeNotes
valuestringUnique among the items
labelstringThe tick's name, and the card's title
descriptionReactNodeUnder the title, and the tick's description
hrefstringMakes the tick a link
targetHTMLAttributeAnchorTarget_blank adds rel="noreferrer noopener"
relstring
disabledbooleanDims the tick and skips it

Accessibility

Preview Rail is a navigation landmark, named by aria-label. Every tick is a link or a button named by its item's label, with the description as its description, and the current one carries aria-current (page on a link). The card repeats what the tick already says, so screen readers skip it.

KeyDoes
TabMoves to the next tick and shows its card
EnterFollows the link, or chooses the item
SpaceChooses the item (buttons)
EscapeHides the card

On a touch screen, a press on the rail lights the tick under the finger and shows its card, a drag along the rail scrubs instead of scrolling the page, and lifting on the rail follows the lit tick. Lifting away from the rail chooses nothing.