SegmentedControl
A linear set of two or more segments
Source
LLM docs
Docs
PackageIcon
Usage
Controlled
Uncontrolled
SegmentedControl can be used with uncontrolled forms the same way as a native input element.
Set the name attribute to include segmented control value in FormData object on form submission.
To control the initial value in uncontrolled forms, use the defaultValue prop.
Example usage of uncontrolled SegmentedControl with FormData:
Data prop
SegmentedControl supports two different data formats:
- An array of primitive values – used when
valueandlabelare the same - An array of objects – used when
valueandlabelare different
Generic value type
SegmentedControl supports generic value type. You can pass primitive values (numbers, strings, boolean, null)
as the type argument. The generic type is used for value, defaultValue, onChange and data props.
Example with strings union:
Disabled
To disable a SegmentedControl item, use the array of objects data format and set disabled: true
on the item that you want to disable. To disable the entire component, use the disabled prop.
Disabled control
Disabled option
React node as label
You can use any React node as a label:
Color
By default, SegmentedControl uses theme.white with shadow in the light color scheme and var(--mantine-color-dark-6) background color for the indicator.
Set the color prop to change the indicator background-color:
Auto contrast
SegmentedControl supports autoContrast prop. If set to true, the label text color will automatically adjust
to ensure optimal contrast against the indicator background color:
Transitions
Change transition properties with:
transitionDuration– all transitions duration in ms,200by defaulttransitionTimingFunction– all transitions timing function,easeby default
No transitions
500ms linear transition
readOnly
Set the readOnly prop to prevent the value from being changed:
Styles API
SegmentedControl supports the Styles API; you can add styles to any inner element of the component with the classNames prop. Follow the Styles API documentation to learn more.
Component Styles API
Hover over selectors to highlight corresponding elements
Accessibility and usability
SegmentedControl uses radio inputs under the hood, so it is accessible by default with no extra steps required if you have text in labels.
The component supports the same keyboard events as a regular radio group.
If you do not have text in labels (for example, when you want to use SegmentedControl with icons only),
use VisuallyHidden to make the component accessible: