Segmented Button
A Segmented button is a linear set of two or more segments, each of which presents a mutually exclusive button.
Use the Segmented Button to group several related buttons of which only one can be active at a time. This component may be used to switch between related modes, eg. display as table/chart, or to toggle different Panels in the application (eg. preview/edit). When using a Segmented Button, the actions should all be related, otherwise, separate buttons should be used.
Example
Usage Rules
Don’t:
- Combine segments with and without icon in one Segmented Button
Variants
Label
You can add a label to let users know what the SegmentedButton is for and also add extra piece of information to the label by including a tooltip.
Icon
Label and Icon
Size
The Segmented button comes in two sizes: small
and medium
.
Tooltip
note
Make sure to pass an empty element on children
key at the Tooltip object when using this option, as on the example below.
Props
SegmentedButton
Name | Type | Default |
---|---|---|
onChange * The handler will be called on a new selection. We pass this callback to the HTML input element.
You can access the value of a newly selected segment with event.target.value (string) |
| — |
items * Array of Segment items.
See props of this component below |
| — |
label The visual label of the SegmentedButton |
| — |
labelIconTooltip The labelIconTooltip content can either be pure text or any rich content wrapped in a React component
The labelIconTooltip content will be shown when hovering the label icon.
The labelIconTooltip position is used to define the positioning of the tooltip
When the labelIconTooltip content is not provided, the label icon will be not shown. |
| — |
size The size of the Segmented Button |
| "medium" |
value Value of checked segment |
| — |
id Internally, this component uses a random id. We use it to associate an input with a label element. As the random id might break snapshot tests it can be overridden by setting an explicit id. |
| — |
css Add custom styles to this component. Use with caution. Learn more here: Link |
| — |
inputFieldCss |
| — |
data-{foo} Data attributes can be used by testing libraries to retrieve components or assert their existence |
| — |
* - the prop is required. |
Object structure of the items
prop
Name | Type | Default |
---|---|---|
label * Label of the segment |
| — |
value * Native HTML attribute: Link |
| — |
iconName Name of the Icon that would appear on the right. Please refer to the full list here: Link | "AddValue" | "AppGrid" | "ArrowCircleLeft" | "ArrowCircleRight" | "ArrowDown" | "ArrowDownLeft" | "A... | — |
iconOnly If the visual label should be hidden |
| false |
id Native HTML attribute: Link .
Internally, this component uses a random id. We use it to associate an input with a label element.
As the random id might break snapshot tests it can be overridden by setting an explicit id. |
| — |
tooltip Add a tooltip when hovering a specific segmented button. More here: Link |
| — |
dataTestId A test id to be used by testing libraries.
It will be added as a "data-testid" attribute on the segment. |
| — |
* - the prop is required. |