Components
Segment group

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

To create a controlled SegmentGroup component, manage the current selected segment using the value prop and update it when the onValueChange event handler is called:

Root Provider

An alternative way to control the segment group is to use the RootProvider component and the useSegmentGroup hook. This way you can access the state and methods from outside the component.

Disabled

To disable a segment, simply pass the disabled prop to the SegmentGroup.Item component:

API Reference

Root

Renders a <div> element.

PropDefaultType
asChild
boolean

Use the provided child element as the default rendered element, combining their props and behavior.

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
Partial<{ root: string label: string indicator: string item: (value: string) => string itemLabel: (value: string) => string itemControl: (value: string) => string itemHiddenInput: (value: string) => string }>

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

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 checkbox is read-only

value
string

The controlled value of the segment group

AttributeDescription
[data-scope]segment-group
[data-part]root
[data-orientation]The orientation of the segment-group
[data-disabled]Present when disabled

Indicator

Renders a <div> element.

PropDefaultType
asChild
boolean

Use the provided child element as the default rendered element, combining their props and behavior.

For more details, read our Composition guide.
AttributeDescription
[data-scope]segment-group
[data-part]indicator
[data-disabled]Present when disabled
[data-orientation]The orientation of the indicator
CSS VariableDescription
--transition-propertyThe transition property value for the Indicator
--leftThe left position value
--topThe top position value
--widthThe width of the element
--heightThe height of the element

ItemControl

Renders a <div> element.

PropDefaultType
asChild
boolean

Use the provided child element as the default rendered element, combining their props and behavior.

For more details, read our Composition guide.
AttributeDescription
[data-scope]segment-group
[data-part]item-control
[data-active]Present when active or pressed

ItemHiddenInput

Renders a <input> element.

PropDefaultType
asChild
boolean

Use the provided child element as the default rendered element, combining their props and behavior.

For more details, read our Composition guide.

Item

Renders a <label> element.

PropDefaultType
value
string

asChild
boolean

Use the provided child element as the default rendered element, combining their props and behavior.

For more details, read our Composition guide.
disabled
boolean

invalid
boolean

ItemText

Renders a <span> element.

PropDefaultType
asChild
boolean

Use the provided child element as the default rendered element, combining their props and behavior.

For more details, read our Composition guide.

Label

Renders a <label> element.

PropDefaultType
asChild
boolean

Use the provided child element as the default rendered element, combining their props and behavior.

For more details, read our Composition guide.
AttributeDescription
[data-scope]segment-group
[data-part]label
[data-orientation]The orientation of the label
[data-disabled]Present when disabled

RootProvider

Renders a <div> element.

PropDefaultType
value
UseRadioGroupReturn

asChild
boolean

Use the provided child element as the default rendered element, combining their props and behavior.

For more details, read our Composition guide.

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.