Selection
Segmented control
A pill of two to five segments with exactly one selected, used to switch the view below it or the kind of thing a form adds.
In kanso-ui as SegmentedButton
Web and native
SegmentedButton in kanso-ui 0.59.0, for React.
import { SegmentedButton } from '@kanso-labs/kanso-ui'A row of two to five joined segments, of which one, or with selectionMode="multiple" several, is chosen.
It follows the Material Design segmented buttons page's outlined set: one 40px track with a shared 1dp rule, fully rounded ends and equal-width segments, and a check before a chosen segment's label. Two deliberate departures: choosing one behaves as a full radio group, and with the check turned off a chosen segment is drawn on the stronger secondary colour, since the spec's own container is too faint to show the choice alone.
What you provide
children: two to fiveSegmentedButton.Segments, each with anid, which is the key selection is reported by.aria-labeloraria-labelledby, one of which is required: nothing else names the set.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
className | ToggleButtonGroupProps['className'] | — | A function may compute the class from the set's render state. |
disallowEmptySelection | boolean | true while one is chosen, false while several may be | Whether the chosen segment stays chosen when it is pressed again. On by default while one is chosen, since a radio group always holds a choice; `false` lets a press clear it, as React Aria's own default does. Off by default while several may be, where any of them can be turned off. |
showSelectedIcon | boolean | false | Deprecated: Kanso's chosen segment draws no check, since its lifted surface and heavier label say which it is. `true` still draws Material Design's check before a chosen segment's label, in place of its icon, and warns once in development. |
style | ToggleButtonGroupProps['style'] | — | A function may compute the style from the set's render state. |
Also takes the props of LabelledByAttribute, Omit<ToggleButtonGroupProps, 'className' | 'disallowEmptySelection' | 'orientation' | 'style'>.
Parts
SegmentedButton.Segment: one segment. Itschildrenare the label and itsid(required) the selection key: a segment without one would keep a pressed state of its own, apart from the group's selection.iconsets an 18dp icon before the label, replaced by the check while chosen; given with no label, the icon is the segment, kept while chosen, and the segment needs anaria-label.isDisabledturns off one segment;disableRippleturns off its ripple.
Example
import { SegmentedButton } from '@kanso-labs/kanso-ui'
<SegmentedButton aria-label="Label" defaultSelectedKeys={['first']}>
<SegmentedButton.Segment id="first">First item</SegmentedButton.Segment>
<SegmentedButton.Segment id="second">Second item</SegmentedButton.Segment>
<SegmentedButton.Segment id="third">Third item</SegmentedButton.Segment>
</SegmentedButton>The design’s classes
k-seg, k-seg--fill, k-seg__item with aria-pressed; bundle.css gives aria-selected and aria-checked the same look, for tab and radio markup.
Maps to SegmentedButton in kanso-ui and react-native-kanso-ui; Kanso calls it SegmentedControl.