Segmented
Slant / Controls
A radiogroup of options with roving focus, in two sizes.
Demo
Usage
import { Segmented } from '@tuttn/slant'
const views = [{ value: 'list', label: 'List' }, { value: 'board', label: 'Board' }] as const
// Controlled: pass value and onValueChange.
const [view, setView] = useState<'list' | 'board'>('board')
<Segmented options={views} value={view} onValueChange={setView} label="Board view" />
// Uncontrolled: leave value out; it starts from defaultValue (or the first option).
// The compact mono variant hugs its options instead of filling the row.
const ranges = [{ value: '7d', label: '7d' }, { value: '1y', label: '1y', disabled: true }] as const
<Segmented size="sm" options={ranges} defaultValue="7d" label="Range" />
// In a form: a name adds a hidden input holding the chosen value.
<Segmented options={views} defaultValue="list" label="Board view" name="view" />Props
| Prop | Type | Default | Description |
|---|---|---|---|
options | readonly SegmentedOption<T>[] | — | The choices, in order. `T` is inferred from their values. |
value | T | — | The chosen value. Pass it to control the group; leave it out to let the group keep its own. |
defaultValue | T | the first enabled option | The value an uncontrolled group starts with. |
onValueChange | (value: T) => void | — | Called with the new value when a click or an arrow key chooses an option. |
label | string | — | The group's accessible name. |
size | 'sm' | 'md' | 'md' | `md` fills its row; `sm` is the compact mono variant that hugs its options. |
disabled | boolean | false | Disables every option. A disabled group is not submitted with its form. |
name | string | — | Submits the group with a form: a hidden input with this name carries the chosen value. |
form | string | — | The id of the form the hidden input belongs to, when the group sits outside it. |
…rest | HTMLAttributes<HTMLDivElement> | — | Other attributes and the ref reach the radiogroup element. |
Under <Slant dir="rtl"> the Left and Right arrows swap, so Right steps back through the options; Up and Down work the same in either direction.