SegmentedControl
Pick exactly one of a few options. The value type is inferred from the options.
Status: stable. Category: Forms.
import { SegmentedControl } from '@glyphui/ui'
Exports: SegmentedControl, segmentedControlStyles.
Notes
- Never deselects: clicking the active option keeps it selected.
SegmentedControl props
| Prop | Type | Default | Description |
|---|---|---|---|
options (required) | readonly SegmentedOption<T>[] | ||
aria-label | string | Required unless the control sits in a <Field label>, which labels it. | |
aria-labelledby | string | ||
className | string | ||
defaultValue | string | ||
fullWidth | boolean | ||
id | string | ||
onValueChange | ((value: T) => void) | ||
size | "sm" | "md" | ||
value | string |
Example: Basic
import { SegmentedControl } from '@glyphui/ui'
import { useState } from 'react'
export default function Example() {
const [view, setView] = useState<'list' | 'board' | 'timeline'>('board')
return (
<SegmentedControl
aria-label="View"
value={view}
onValueChange={setView}
options={[
{ value: 'list', label: 'List' },
{ value: 'board', label: 'Board' },
{ value: 'timeline', label: 'Timeline' },
]}
/>
)
}
Example: Full width
import { SegmentedControl } from '@glyphui/ui'
export default function Example() {
return (
<div className="max-w-sm">
<SegmentedControl
aria-label="Billing period"
fullWidth
defaultValue="yearly"
options={[
{ value: 'monthly', label: 'Monthly' },
{ value: 'yearly', label: 'Yearly · save 20%' },
]}
/>
</div>
)
}