Separator

Slant / Layout

A horizontal or vertical rule, decorative or announced, with an optional label.

Demo

Usage

@tuttn/slant
import { Row, Separator, Stack, Text } from '@tuttn/slant'

// Decorative by default: drawn, not announced.
<Stack><Text>Above</Text><Separator /><Text>Below</Text></Stack>

// Between groups of actions in a row: a vertical rule as tall as the row,
// announced as a separator.
<Row>
  <Button>Edit</Button>
  <Separator orientation="vertical" decorative={false} />
  <Button tone="danger">Delete</Button>
</Row>

// A label in the middle, the line on both sides.
<Separator>or</Separator>

Props

PropTypeDefaultDescription
orientation'horizontal' | 'vertical''horizontal'A rule across the content (horizontal), or between items in a row (vertical, stretching to the row's height).
decorativebooleantrueDraws the rule for looks only (`role="none"`). Set it to false when the rule divides content a reader should hear about: it becomes a `role="separator"`.
childrenReactNode—A short label in the middle of the rule ("or"), with the line drawn on both sides. Assistive technology reads it as text only while the separator is decorative; a `role="separator"` hides its content, so give that one an `aria-label`.
…restHTMLAttributes<HTMLDivElement>—The ref, className, style and other attributes go on the root div.

A decorative separator has role="none": it draws a line and nothing more, and a label inside it is read as plain text. With decorative={false} it is a role="separator", with aria-orientation="vertical" when vertical. A separator's content is hidden from assistive technology, so a labelled one that isn't decorative should also get an aria-label.

The line is --sl-line, one pixel thick, with no margin of its own: the gap of the Stack or Row around it does the spacing. A vertical separator stretches to its flex parent's height.