Forms

SegmentedControl

Compact selector for a small set of bindable options and route-backed links.

import { SegmentedControl } from '@lostgradient/cinder';
formselection
01

Overview

Reference usage

Compact segmented selector for a small fixed set of options, including bindable selections and route-backed navigation links.

Usage

svelte
<script lang="ts">
  import { Segment } from '@lostgradient/cinder';
  import { SegmentedControl } from '@lostgradient/cinder';
</script>

<SegmentedControl id="view-filter" label="View filter" variant="navigation">
  <Segment href="/costs?source=actual" current>Actual</Segment>
  <Segment href="/costs?source=forecast">Forecast</Segment>
</SegmentedControl>

Width and selection

A SegmentedControl is as wide as its options and no wider: it never stretches to fill a grid cell or a column, and its options never wrap onto a second line. When its options do not fit the room it has, a horizontal control falls back to a stacked radio list, one full-width option per row, so no option is clipped mid-word; it is the attached row again once the room fits them. A density="toolbar" control never stacks: a toolbar is one row and owns its own overflow. The arrow keys reach every option in both forms. fullWidth is the one explicit opt-in that spans the container.

The selected (or pressed) segment is a raised pill with a 1px ring in the control tier (--cinder-border-control), so the selection clears 3:1 against the track in both themes; the segmented-control:selected-indicator:* contrast pairings hold it there. A horizontal control follows the painted height of a Button of the same size. Under a coarse pointer, each horizontal option's 44px hit area stays inside the scroll box and takes no layout space. The selected tab in a tablist draws its indicator in place of the extended hit area. A stacked control's rows keep a list row's minimum.

Compact spacing

An attached horizontal option pads 12px inline at sm and md, which keeps a label off the separator between options. spacing="compact" pads --cinder-space-2 (8px) instead, so a few short labels fit one row on a phone, such as the six tabs of a run page in a variant="navigation" control with density="toolbar". It is an explicit prop and never something the control decides from its width, so a page can predict where its labels sit. Detached, vertical and lg options keep their own padding, and the resolved value is carried as data-cinder-spacing (default or compact). Compact only narrows the padding: a control still scrolls sideways when its options do not fit even at 8px.

svelte
<script lang="ts">
  import { Segment, SegmentedControl } from '@lostgradient/cinder';
</script>

<SegmentedControl
  id="run-tabs"
  label="Run sections"
  variant="navigation"
  density="toolbar"
  spacing="compact"
>
  <Segment href="#now" current>Now</Segment>
  <Segment href="#history">History</Segment>
  <Segment href="#failure">Failure</Segment>
</SegmentedControl>

Disabled options

Keep an unavailable choice visible when people need to know it exists. Add a note or use aria-describedby to explain why it is unavailable.

In attached and detached horizontal controls, an idle disabled option pairs disabled text with a flat --cinder-fill-disabled background. A selected disabled option keeps its raised pill. A disabled tab or navigation option uses disabled text on a transparent background.

Overflow to a Select

overflow="select" keeps every option on screen when the segments are wider than the room the control has, such as four long choices on a phone. The control then draws the same options as a Select with the same accessible name, the same value and the same change callback, and returns to the strip when the room is there again. The strip stays in the document, out of sight and out of reach (aria-hidden, inert), so the control knows how wide the segments are by themselves and the choice never flips back and forth on its own: it measures the strip against the room its parent gives it, and showing the Select changes neither. It applies to a single-choice radiogroup; a tab list, a navigation and a multiple selection ignore it, because each is something a Select does not hold. Without the prop (scroll, the default) a control that does not fit scrolls sideways, as before.

svelte
<script lang="ts">
  import { Segment, SegmentedControl } from '@lostgradient/cinder';
</script>

<SegmentedControl id="then" label="Then" value="webhook" overflow="select">
  <Segment value="webhook">Send a webhook</Segment>
  <Segment value="workflow">Start a workflow</Segment>
  <Segment value="notify">Notify me</Segment>
  <Segment value="plugin">Run an action from a plugin</Segment>
</SegmentedControl>

Counts

A Segment takes a count, drawn after its label in a muted, tabular figure ("Waiting on you 2"). The count is part of the segment's accessible name ("Waiting on you, 2"), and zero still shows ("Running 0"). Only undefined hides it.

svelte
<script lang="ts">
  import { Segment, SegmentedControl } from '@lostgradient/cinder';
</script>

<SegmentedControl id="status" label="Status" selectionMode="single" value="all">
  <Segment value="all" count={19}>All</Segment>
  <Segment value="waiting" count={2}>Waiting on you</Segment>
</SegmentedControl>
Live preview

Basic segmented control

Document view

Current view: rendered

02

When to use

Use when
  • Choosing one of two to five mutually exclusive options that all fit on screen at once.
  • Picking a view filter where seeing every option beats hiding them inside a toggle or tabs control.
  • Rendering route-backed filters as real links with `variant="navigation"` and `Segment href`.
  • Fitting a handful of short tabs, such as six, on one phone row with `spacing="compact"` (8px padding).
  • Keeping 44px touch targets inside the scroll box on coarse pointers.
  • Showing an unavailable option with disabled text and flat fill.
Avoid when
  • Toggling a single binary on or off — use toggle or checkbox instead.
  • Switching between panels of associated content — use tabs instead.
03

Examples

Basic segmented control

A compact radio-group control with keyboard navigation.

Segments with counts

A segment takes a count, drawn after the label in a muted, tabular figure. The count is part of the accessible name ("Waiting on you, 2"), and zero still shows.

Multi-select segmented control

Multiple options can be toggled independently. Pass a SvelteSet to track selection.

Navigation route filters

Use the navigation variant with linked segments when each option should update the URL.

Counts that are still loading

count="pending" draws a dash where the number will be ("All –") and reads as "All, loading", so the segments keep their width while the data arrives.

Sizing — size vs. toolbar density

Compares the three sizes (sm/md/lg) against `density="toolbar"`. Toolbar density resolves to the same compact visual size as `size="sm"` and ignores any explicit `size` value, so the toolbar-with-md and toolbar-with-lg controls render identically to the toolbar-without-size control and to `size="sm"`.

Tablist variant

The `variant="tablist"` treatment for picker-shaped controls that switch between externally owned panels. Unlike the default radiogroup, the tablist has no enclosing surface and marks the selected tab with an accent underline (horizontal) or inline-start bar (vertical). Each tab wires `aria-controls` to a panel rendered elsewhere in the layout. See docs/decisions/segmented-control-tablist-variant.md.

04

Props

Props for segmented-control
Name
Type
Default
Description
id required text Unique identifier for the control.
value bindable discriminated-union Currently selected value.
label required text Accessible label for the group.
name text Native form field name. Renders hidden input(s) carrying the selected value(s).
labelVisible boolean true Whether the label is visibly rendered. Set false to visually hide it while keeping it available to assistive technology.
description text Helper text under the control, wired into the group's aria-describedby.
note text Neutral explanation under the helper text, wired into aria-describedby. Not an error and not a warning.
error text Validation error under the control, with a warning glyph; sets aria-invalid="true" on the group.
errorAction Snippet | undefined Rendered after the error message inside the same live region, such as a quiet "Try again".
disabled boolean false Disable the whole control.
size 'sm' | 'md' | 'lg' | undefined 'md' Requested visual size of the control. Defaults to "md". The control's outer height is the shared --cinder-control-height-* step for the size (sm 28px, md 32px, lg 40px), the same as a Button or Input of that size. The resolved size is reflected as data-cinder-size on the root; when density="toolbar" is set, the resolved size is forced to "sm" and any explicit size value is ignored. size="md" option text uses --cinder-text-sm; size="sm" and density="toolbar" use --cinder-text-xs; size="lg" uses --cinder-text-sm.
density 'toolbar' | undefined Opt the control into compact toolbar sizing so it lines up cleanly with sibling Button (size="sm"), Chip (density="toolbar"), and other toolbar elements. Toolbar density resolves to the compact "sm" font and padding scale — when set, any explicit size value is ignored and the resolved size (data-cinder-size) is "sm", so the control's outer height is --cinder-control-height-sm and matches sibling toolbar controls.
spacing 'default' | 'compact' | undefined 'default' Inline padding of each option in an attached horizontal control (COR-2794). default keeps --cinder-space-3 (12px) at sm and md, which holds a label off the separator between options. compact pads --cinder-space-2 (8px) so a few short labels, such as six tabs, fit one row on a phone. It is an explicit prop, never something the control decides from its width, so a page can predict where its labels sit. Detached, vertical and lg options keep their own padding; the resolved value is reflected as data-cinder-spacing on the root.
orientation 'horizontal' | 'vertical' | undefined 'horizontal' Layout orientation.
detached boolean false Render segments as detached individual buttons instead of a unified strip.
fullWidth boolean false Stretch the control to fill available width.
variant 'radiogroup' | 'tablist' | 'navigation' | undefined 'radiogroup' ARIA interaction pattern. Use navigation for route-backed links.
selectionMode discriminated-union 'single' Selection mode. "single" allows exactly one segment to be selected at a time; "multiple" allows any number of segments to be selected simultaneously. Default "single".
selectionRequired discriminated-union true When true, clicking the already-selected option is a no-op. When false, clicking the selected option clears value to undefined.
overflow 'scroll' | 'select' | undefined 'scroll' What the control does when its segments are wider than the room it has (COR-2181). scroll (the default) keeps the strip and lets it scroll sideways, as it always has. select draws the same options as a Select with the same accessible name, so every option stays on screen on a phone; the segments stay in the document, hidden, so the control knows how much room they need and returns to the strip when the room is there. It applies to a single-choice radiogroup only.
onValueChange ((value: T) => void) | undefined Called when the selected value changes (single mode only).
children required snippet Child <Segment> elements.