Segmented
Segmented control for mutually exclusive options, ideal for view switchers.
Basic usage
Basic usage
Current value: list
The first row is a controlled usage that shows the current value; the second row uses block to fill the container, and disabled: true inside an option object disables that single option; the third row uses disabled to disable the whole group. Options also accept a string shortcut:
import { useState } from 'react'
import { LhSegmented } from '@lh-ui/react'
export default function Demo() {
const [value, setValue] = useState('list')
return <LhSegmented value={value} onChange={setValue} options={['List', 'Card', 'Table']} />
}
LhSegmented Props
| Prop | Description | Type | Options | Default |
|---|---|---|---|---|
| value | Controlled current value (plus's modelValue) | string | number | — | — |
| defaultValue | Uncontrolled default value | string | number | — | — |
| options | Options (string shortcut or object) | LhSegmentedInput[] | — | — |
| disabled | Disable the whole group | boolean | — | false |
| block | Fill the container | boolean | — | false |
| sx | Shorthand layout props | SxProps | — | — |
LhSegmented events
| Event | Description | Callback signature | Vue equivalent |
|---|---|---|---|
| onChange | Selected option changed (triggered by click and arrow keys) | (value: string | number) => void | @update:modelValue / @change |
Accessibility
The root element is a role="radiogroup" and each option is a real focusable button (role="radio" + aria-checked). With roving tabindex only the focused stop is tabbable; the arrow keys move in four directions, skipping disabled options and wrapping around.
Styles
import '@lh-ui/react/style/segmented'