Segment
freeSegment switches between a few related options from one compact control.
Installation
Add this component with the NateUI CLI.
Examples
Basic
Size
Multiple Selection
With Icons
Disabled
Controlled
Active view: board
API
Segment is a compound control: the Segment root holds selection state and renders the sliding indicator, while each Segment.Item is one selectable option. In single mode selecting the active item again clears the selection; in multiple mode each item toggles independently.
Segment
| Prop | Description | Type | Default |
|---|---|---|---|
selectionType | Whether one item or several items can be active at once. | 'single' | 'multiple' | 'single' |
value | Active value in controlled mode. A string for single selection, an array for multiple. | SegmentValue | - |
defaultValue | Initial value when uncontrolled. A string for single selection, an array for multiple. | SegmentValue | - |
onChange | Fires with the new value whenever the selection changes. | (value: SegmentValue) => void | - |
size | Control size applied to every item, unless an item sets its own. | ControlSize | 'md' |
className | Class names for the root element. | string | - |
ref | Ref forwarded to the root element. | Ref<HTMLDivElement> | - |
...nativeProps | Native props for the root div (except onChange). | Omit<ComponentProps<'div'>, 'onChange'> | - |
Segment.Item
| Prop | Description | Type | Default |
|---|---|---|---|
value | Unique value that identifies this item within the group. | string | - |
children | Item content, or a render function that receives the item state for a custom look. | ReactNode | ((params: SegmentItemRenderProps) => ReactNode) | - |
disabled | Prevent this item from being selected and dim it. | boolean | false |
size | Control size for this item, overriding the group size. | ControlSize | - |
className | Class names for the item button. | string | - |
ref | Ref forwarded to the item button. | Ref<HTMLButtonElement> | - |
...nativeProps | Native button props (except children). | Omit<ComponentPropsWithRef<'button'>, 'children'> | - |