Skip to content

Divider

Divider

A line that separates content, horizontally or vertically, optionally with a label in the middle.

- A plain horizontal divider renders an <hr>; a vertical or labelled divider renders a <div role="separator"> (as replaces the element in every case). children that render nothing ('', or an array, Set or generator of only empty items, such as an empty .map() result) are no label; 0 is one.
- A labelled divider is **one** separator named by its label (aria-labelledby); the two line segments around the label are presentational (aria-hidden). A consumer aria-label names it instead, and a consumer aria-labelledby is joined with the label.
- Vertical dividers set aria-orientation="vertical" and use logical borders (RTL-safe).

Examples

Default

export const Default: Story = {
  decorators: [
    (Story) => (
      <div style={{ width: 400 }}>
        <Story />
      </div>
    ),
  ],
};

Vertical

export const Vertical: Story = {
  args: {
    orientation: 'vertical',
  },
  decorators: [
    (Story) => (
      <div style={{ height: 48, display: 'flex', alignItems: 'center' }}>
        <Story />
      </div>
    ),
  ],
};

With Text

export const WithText: Story = {
  args: {
    children: 'OR',
  },
  decorators: [
    (Story) => (
      <div style={{ width: 400 }}>
        <Story />
      </div>
    ),
  ],
};

Vertical With Text

export const VerticalWithText: Story = {
  args: {
    orientation: 'vertical',
    children: 'OR',
  },
  decorators: [
    (Story) => (
      <div style={{ height: 120, display: 'flex', alignItems: 'stretch' }}>
        <Story />
      </div>
    ),
  ],
};

Appearances

export const Appearances: Story = {
  argTypes: { appearance: { control: false } },
  render: (args) => (
    <div className="flex w-96 flex-col gap-4">
      {(['default', 'subtle', 'strong', 'brand'] as const).map((appearance) => (
        <Divider key={appearance} {...args} appearance={appearance}>
          {appearance}
        </Divider>
      ))}
    </div>
  ),
};

Inset

export const Inset: Story = {
  render: (args) => (
    <div className="w-96">
      <Divider {...args} />
      <Divider {...args} inset />
      <Divider {...args} inset>
        Inset with a label
      </Divider>
    </div>
  ),
};

Align Content

export const AlignContent: Story = {
  argTypes: { alignContent: { control: false } },
  render: (args) => (
    <div className="flex w-96 flex-col gap-4">
      {(['start', 'center', 'end'] as const).map((alignContent) => (
        <Divider key={alignContent} {...args} alignContent={alignContent}>
          {alignContent}
        </Divider>
      ))}
    </div>
  ),
};

Props

NameTypeRequiredDefaultDescription
orientation'horizontal' | 'vertical'No'horizontal'

Orientation of the divider line.

appearance'default' | 'subtle' | 'brand' | 'strong'No'default'

How the line looks: 'default' is the border color, 'subtle' a fainter line (the border color at half strength), 'strong' a firmer one and 'brand' the brand color. Rendered as data-appearance. Fluent's appearance.

insetbooleanNofalse

Insets the divider from the edges of its container by 12px along its length, so the line stops short of both ends. Rendered as a boolean data-inset. Fluent's inset.

alignContent'start' | 'center' | 'end'No'center'

Where the label sits along a divider that has one: 'center' between two lines of equal length, 'start' or 'end' with a short line (8px) on that side and the long line on the other. 'start' and 'end' follow the writing direction. Rendered as data-align-content on a labelled divider; a divider without a label ignores it. Fluent's alignContent.

refReact.Ref<HTMLElement>No

Ref to the rendered element. Typed HTMLElement for every as, because the default element depends on the props: an <hr> for a plain horizontal divider, a <div> otherwise.

slotProps{ line?: SlotPart<'div'>; label?: SlotPart<'span'> }No

Props for the elements a labelled divider draws, by part, merged into each part's own: your classes after the part's (yours win a conflict), your styles over its styles, your attributes and handlers added, your ref attached. Every attribute the divider sets on a part is locked. A part takes no children (the label's content is the divider's children). A divider without a label draws no part and ignores them.

asReact.ElementTypeNo'hr'

Render as a different element or component (its props are type-checked).

Any other prop is passed to the element it renders (HTMLHRElement).

Parts

  • line
  • label

Stable class names

PartClass
rootwave-divider
linewave-divider__line
labelwave-divider__label