SegmentedControl Controlled Mode
The SegmentedControl supports both controlled and uncontrolled usage:
- In controlled mode, the
valueprop determines the selected item, and the parent updates it in response to thechangeevent. - In uncontrolled mode,
defaultValuesets the initial selection, and the component manages later selection changes.
Controlling the Value
Set the value prop to a string that matches an item's value. The matching item appears selected. When a user selects a different item, the change event emits the new string. Clicking the selected item does not emit the event. If no item matches value, no item is selected.
In controlled mode, update value in the change event handler. If the parent does not update the prop, the component continues to show the selection represented by its current value.
The following demo updates the parent value in response to each selection:
Default Value
Set defaultValue to a string that matches an item's value to choose the initial selection. The component reads it on initial render and manages later selections internally. Changing defaultValue afterward has no effect. If you omit both value and defaultValue, no item is selected initially.
The following demo sets the initial selection with defaultValue: