Inputs
SegmentedControl
Single-choice control with a sliding thumb. It always has a selection and honors prefers-reduced-motion.
<script>
import { SegmentedControl } from "@codeatlasdev/ui";
let period = $state("month");
</script>
<SegmentedControl
aria-label="Period"
bind:value={period}
items={[{ value: "week", label: "Week" }, { value: "month", label: "Month" }]}
/>
Unlike ToggleGroup, exactly one item is always selected: when value is unset it starts on the first enabled item. Give the control an aria-label since it has no visible heading, and an aria-label on every icon-only item. Arrow keys move between items.
Default
Text items, and text items with icons.
value: month
Code
Small, full width, disabled item
Code
Props
| Prop | Type | Default | Description |
|---|---|---|---|
value | string | first enabled item | Bindable selected value. |
items | ToggleGroupItem[] | – | { value, label?, icon?, disabled?, 'aria-label'? }. |
size | 'sm' | 'md' | 'md' | Item height. |
fullWidth | boolean | false | Stretches the control to the container width. |
disabled | boolean | false | Disables the whole control. |
aria-label | string | – | Accessible name of the control. |
class | string | – | Extra classes on the root. |
onchange | (value: string) => void | – | Called when the selection changes. |