Segment Group
Organizes and navigates between sections in a view.
Anatomy
<SegmentGroup.Root>
<SegmentGroup.Indicator />
<SegmentGroup.Item>
<SegmentGroup.ItemText />
<SegmentGroup.ItemControl />
<SegmentGroup.ItemHiddenInput />
</SegmentGroup.Item>
</SegmentGroup.Root>
Examples
Controlled
Use value and onValueChange to control the selected segment.
Root Provider
Use RootProvider with the useSegmentGroup hook to access the state and methods from outside the component.
Disabled
Pass disabled to a SegmentGroup.Item to disable that segment.
API Reference
Root
Defines the <div> element.
| Attribute | Default | Type |
|---|---|---|
asChild | booleanUse the provided child element as the default rendered element, combining their props and behavior. Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`. For more details, read our Composition guide. | |
defaultValue | stringThe initial value of the checked radio when rendered. Use when you don't need to control the value of the segment group. | |
disabled | booleanIf `true`, the segment group will be disabled | |
form | stringThe associate form of the underlying input. | |
id | stringThe unique identifier of the machine. | |
ids | ElementIdsThe ids of the elements in the radio. Useful for composition. | |
invalid | booleanIf `true`, the segment group is marked as invalid. | |
name | stringThe name of the input fields in the radio (Useful for form submission). | |
onValueChange | (details: ValueChangeDetails) => voidFunction called once a radio is checked | |
orientation | 'horizontal' | 'vertical'Orientation of the segment group | |
readOnly | booleanWhether the segment group is read-only | |
render | ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<RadioGroupRootState>Render the part as a custom element, combining their props and behavior. Pass an element to have the part's props merged into it, or a function to control the merge yourself and read the part's state. | |
required | booleanIf `true`, the segment group is marked as required. | |
value | stringThe controlled value of the segment group |
| Attribute | Description |
|---|---|
[data-radio-group-root] | <uid> |
[data-orientation] | The orientation of the segment-group |
[data-disabled] | Present when disabled |
[data-invalid] | Present when invalid |
[data-required] | Present when required |
Indicator
Defines the <div> element.
| Attribute | Default | Type |
|---|---|---|
asChild | booleanUse the provided child element as the default rendered element, combining their props and behavior. Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`. For more details, read our Composition guide. | |
render | ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<EmptyState>Render the part as a custom element, combining their props and behavior. Pass an element to have the part's props merged into it, or a function to control the merge yourself and read the part's state. |
| Attribute | Description |
|---|---|
[data-radio-group-indicator] | <uid> |
[data-disabled] | Present when disabled |
[data-orientation] | The orientation of the indicator |
[data-instant] |
| CSS Variable | Description |
|---|---|
--left | The left position value |
--top | The top position value |
--width | The width of the element |
--height | The height of the element |
ItemControl
Defines the <span> element.
| Attribute | Default | Type |
|---|---|---|
asChild | booleanUse the provided child element as the default rendered element, combining their props and behavior. Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`. For more details, read our Composition guide. | |
render | ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<EmptyState>Render the part as a custom element, combining their props and behavior. Pass an element to have the part's props merged into it, or a function to control the merge yourself and read the part's state. |
| Attribute | Description |
|---|---|
[data-radio-group-item-control] | <uid> |
[data-active] | Present when active or pressed |
[data-focus] | Present when focused |
[data-focus-visible] | Present when focused with keyboard |
[data-disabled] | Present when disabled |
[data-readonly] | Present when read-only |
[data-state] | "checked" | "unchecked" |
[data-hover] | Present when hovered |
[data-invalid] | Present when invalid |
[data-orientation] | The orientation of the item |
[data-indicator-pending] | Present while the indicator isn't in place yet (server render or not measured) |
ItemHiddenInput
Defines the <input> element.
| Attribute | Default | Type |
|---|---|---|
asChild | booleanUse the provided child element as the default rendered element, combining their props and behavior. Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`. For more details, read our Composition guide. | |
render | ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<EmptyState>Render the part as a custom element, combining their props and behavior. Pass an element to have the part's props merged into it, or a function to control the merge yourself and read the part's state. |
Item
Defines the <label> element.
| Attribute | Default | Type |
|---|---|---|
value | string | |
asChild | booleanUse the provided child element as the default rendered element, combining their props and behavior. Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`. For more details, read our Composition guide. | |
disabled | boolean | |
invalid | boolean | |
render | ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<RadioGroupItemState>Render the part as a custom element, combining their props and behavior. Pass an element to have the part's props merged into it, or a function to control the merge yourself and read the part's state. |
| Attribute | Description |
|---|---|
[data-radio-group-item] | <uid> |
[data-focus] | Present when focused |
[data-focus-visible] | Present when focused with keyboard |
[data-disabled] | Present when disabled |
[data-readonly] | Present when read-only |
[data-state] | "checked" | "unchecked" |
[data-hover] | Present when hovered |
[data-invalid] | Present when invalid |
[data-orientation] | The orientation of the item |
[data-indicator-pending] | Present while the indicator isn't in place yet (server render or not measured) |
ItemText
Defines the <span> element.
| Attribute | Default | Type |
|---|---|---|
asChild | booleanUse the provided child element as the default rendered element, combining their props and behavior. Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`. For more details, read our Composition guide. | |
render | ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<EmptyState>Render the part as a custom element, combining their props and behavior. Pass an element to have the part's props merged into it, or a function to control the merge yourself and read the part's state. |
| Attribute | Description |
|---|---|
[data-radio-group-item-text] | <uid> |
[data-focus] | Present when focused |
[data-focus-visible] | Present when focused with keyboard |
[data-disabled] | Present when disabled |
[data-readonly] | Present when read-only |
[data-state] | "checked" | "unchecked" |
[data-hover] | Present when hovered |
[data-invalid] | Present when invalid |
[data-orientation] | The orientation of the item |
[data-indicator-pending] | Present while the indicator isn't in place yet (server render or not measured) |
Label
Defines the <span> element.
| Attribute | Default | Type |
|---|---|---|
asChild | booleanUse the provided child element as the default rendered element, combining their props and behavior. Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`. For more details, read our Composition guide. | |
render | ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<EmptyState>Render the part as a custom element, combining their props and behavior. Pass an element to have the part's props merged into it, or a function to control the merge yourself and read the part's state. |
| Attribute | Description |
|---|---|
[data-radio-group-label] | <uid> |
[data-orientation] | The orientation of the label |
[data-disabled] | Present when disabled |
[data-invalid] | Present when invalid |
[data-required] | Present when required |
RootProvider
Defines the <div> element.
| Attribute | Default | Type |
|---|---|---|
value | UseRadioGroupReturn | |
asChild | booleanUse the provided child element as the default rendered element, combining their props and behavior. Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`. For more details, read our Composition guide. | |
render | type ONLY_FOR_FORMAT =
ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<RadioGroupRootProviderState>Render the part as a custom element, combining their props and behavior. Pass an element to have the part's props merged into it, or a function to control the merge yourself and read the part's state. |
Accessibility
Complies with the Radio WAI-ARIA design pattern.
Keyboard Support
| Key | Description |
|---|---|
Tab | Moves focus to either the checked radio item or the first radio item in the group. |
Space | When focus is on an unchecked radio item, checks it. |
ArrowDown | Moves focus and checks the next radio item in the group. |
ArrowRight | Moves focus and checks the next radio item in the group. |
ArrowUp | Moves focus to the previous radio item in the group. |
ArrowLeft | Moves focus to the previous radio item in the group. |