Segmented control
BetaFormsOpen in the workshop
Two to five short, mutually exclusive views or modes, side by side.
.xg-segmented > label > input[type=radio] + spanExample and markup
Live, from xg-ui.css and xg-ui.js. Switch the brand and mode on the example itself, or for the whole site in the header.
Markup
<div class="xg-segmented" role="radiogroup" aria-label="Granularity">
<label>
<input type="radio" name="gran" checked>
<span>Day</span>
</label>
<label>
<input type="radio" name="gran">
<span>Week</span>
</label>
<label>
<input type="radio" name="gran">
<span>Month</span>
</label>
</div>States
Hover, focus and pressed are forced here with .is-hover, .is-focus and .is-active so they can be seen side by side; in a product they come from :hover, :focus-visible and :active.
| State | Segmented |
|---|---|
| First selected | |
| Middle selected |
When to use it
Use it for
chart granularity (Day | Week | Month), table density, a list/grid view.
Not for
navigation between pages (Tabs); settings saved with a form (Radio).
Rules
- Labels are one or two words. Same width is not required.
- Changing it updates the view at once, without a Save.
Accessibility
- Built from native radios, so arrow keys and screen readers work without script. Wrap in role="radiogroup" with aria-label.
Every color pair this component uses is measured for both brands in light and dark on the Accessibility page.
Related
Also in Forms: Input, Textarea, Select, Checkbox, Radio, Switch, Search field, Date-range picker, Form layout. Used in the patterns Dashboard, Reporting table.
Status Beta: usable; class names may still change in a minor release, with a note (see Releasing).