Segment Group

Organizes and navigates between sections in a view.

Loading...

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.

AttributeDefaultType
asChild
boolean

Use 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
string

The initial value of the checked radio when rendered. Use when you don't need to control the value of the segment group.

disabled
boolean

If `true`, the segment group will be disabled

form
string

The associate form of the underlying input.

id
string

The unique identifier of the machine.

ids
ElementIds

The ids of the elements in the radio. Useful for composition.

invalid
boolean

If `true`, the segment group is marked as invalid.

name
string

The name of the input fields in the radio (Useful for form submission).

onValueChange
(details: ValueChangeDetails) => void

Function called once a radio is checked

orientation
'horizontal' | 'vertical'

Orientation of the segment group

readOnly
boolean

Whether 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
boolean

If `true`, the segment group is marked as required.

value
string

The controlled value of the segment group

AttributeDescription
[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.

AttributeDefaultType
asChild
boolean

Use 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.

AttributeDescription
[data-radio-group-indicator]<uid>
[data-disabled]Present when disabled
[data-orientation]The orientation of the indicator
[data-instant]
CSS VariableDescription
--leftThe left position value
--topThe top position value
--widthThe width of the element
--heightThe height of the element

ItemControl

Defines the <span> element.

AttributeDefaultType
asChild
boolean

Use 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.

AttributeDescription
[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.

AttributeDefaultType
asChild
boolean

Use 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.

AttributeDefaultType
value
string

asChild
boolean

Use 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.

AttributeDescription
[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.

AttributeDefaultType
asChild
boolean

Use 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.

AttributeDescription
[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.

AttributeDefaultType
asChild
boolean

Use 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.

AttributeDescription
[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.

AttributeDefaultType
value
UseRadioGroupReturn

asChild
boolean

Use 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

KeyDescription
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.