Segmented Control

A row of options where exactly one is selected. Use it to switch a view or a setting in place, like a period or a layout.

General

Give each item a value, start on one with initialValue and name the group with aria-label.

Controlled

Pass value and onChange to keep the selection in your own state.

Full width

With fullWidth, the group fills its container and the items share the space.

Disabled

Disable one item, or the whole group.

APIs

SegmentedControl.Props

AttributeDescriptionTypeAccepted valuesDefault
valueselected item, to control itstring | number--
initialValueitem selected on the first renderstring | number--
onChangecalled with the value of the chosen item(value: string | number) => void--
disableddisables every itemboolean-false
fullWidthfills the width of the containerboolean-false
...native props, passed to the divHTMLAttributes'aria-label', 'id', ...-

SegmentedControl.Item.Props

AttributeDescriptionTypeAccepted valuesDefault
valueidentifies the item in value and onChangestring | number--
disabledthe item cannot be chosenboolean-false
...native props, passed to the radio inputInputHTMLAttributes'id', ...-

Ref

The ref of SegmentedControl points at the div, and the ref of each item at its radio input.

Accessibility

The group is a radiogroup and each item is a native radio, so a screen reader announces the name of the group, the option and its position. Name the group with aria-label. Tab moves focus into the group on the selected item, and the arrow keys move between the items and select the one in focus. The selected item is not shown by color alone: it also gets a raised background.

Edit this page on GitHub