Skip to content

Segmented control

Selects one option from a compact set of segments.

segmented-control-demo.tsx

Installation

The CLI adds the files, packages, theme variables, and Tailwind plugin that this component uses. Before you run it, set up your project.

Usage

Set `name` on the control to submit the value with a form. Each segment renders a hidden radio input.

project-view.tsx

Composition

  • SegmentedControl

    Owns the value. The indicator follows the checked segment.

    • SegmentedControlItemRepeats

      One segment. Its value is the value that the control stores.

SegmentedControlContext Renders a function with the radio-group api: value, setValue, clearValue, focus, and getItemState.

Controlled

Showing

Last 7 days

segmented-control-controlled-demo.tsx

Icons

Mark the icon aria-hidden so the label stays the accessible name.

segmented-control-icons-demo.tsx

Sizes

xs and sm expand the hit area to 44px on touch screens.

segmented-control-sizes-demo.tsx

Vertical

Studio North is due October 18. The final review covers the checkout, the confirmation email, and the delivery window.

segmented-control-vertical-demo.tsx

Disabled

Plan

Billing period

segmented-control-disabled-demo.tsx

API reference

SegmentedControl

size: "xs" | "sm" | "md" | "lg" | "xl" = "md"
Sets the height, padding, and text size of every segment.
fullWidth: boolean = false
Stretches the control and its segments to the width of the parent.
aria-label: string = "Segments"
Names the radio group. Change it to match the choice, such as View or Billing period.
value: string | null
The selected value, controlled.
defaultValue: string | null
The selected value at first, uncontrolled.
onChange: (value: string) => void
Called with the new value when the selection changes.
onValueChange: (value: string) => void
Alias for onChange. Both run when both are set.
name: string
Submits the selected value with a form. Each segment renders a hidden radio input.
form: string
Associates the hidden inputs with a form by id.
isDisabled: boolean = false
Disables every segment.
isInvalid: boolean = false
Marks the group as invalid.
isRequired: boolean = false
Requires a selection before the form submits.
isReadOnly: boolean = false
Keeps the value but stops changes.
orientation: "horizontal" | "vertical" = "horizontal"
Lays the segments in a row or a column.
dir: "ltr" | "rtl"
Sets the writing direction. The control also inherits the direction of its parent.
ids: ElementIds
Sets the ids of the group, indicator, and segments.
getRootNode: () => ShadowRoot | Document | Node
Resolves the document in custom environments such as iframes.

SegmentedControlItem

value: stringRequired
The value that this segment sets.
isDisabled: boolean = false
Disables this segment only.
children: ReactNodeRequired
The segment content. Add an icon and a label when the label alone is not clear.

SegmentedControlContext

Renders no DOM. Its children receive the radio-group api, including value, setValue, clearValue, focus, and getItemState.

children: (api: SegmentedControlApi) => ReactNodeRequired
Draws custom content for the current api. Call it inside SegmentedControl.