Button Group
Groups a collection of similar actions together.
When to use
- If you need to emphasize context of similar actions.
- If a single option or multiple options of the set may be selected.
Examples
Controlled Behaviour
In radio
mode, the button group functions similarly to a radio group. Only one button can be "selected" at a time.
In checkbox
mode, the button group functions similarly to a group of checkboxes. Multiple buttons can be "selected" at the same time.
You can disable the entire button group as in the example above. Or you can disable isolated buttons as in the example below.
As with many of our components, there is also an uncontrolled version, StatefulButtonGroup
, which manages its own state. If mode
is set to radio
or checkbox
, this stateful version of the component will adapt to keep track of the selected
value(s).
API
ButtonGroup props
Name | Type | Default | Description |
---|---|---|---|
activateOnFocus | boolean | false | Indicates when focusing/navigating using arrow keys, button should also be selected. |
children | react node | Buttons within the group | |
className | string | Enriched style to be provided to ButtonGroup | |
disabled | boolean | false | Indicates that the button group is disabled |
intent | 'default' | 'ai' | Defines the intent of the ButtonGroup. | |
onClick | function | Function called when any button is clicked. | |
overrides | custom | Lets you customize all aspects of the component. | |
selected | array | Defines which buttons are selected | |
shape | 'default' | 'square' | 'pill' | Supported with space theme only. Defines the shape of the button. This prop is directly passed to the children. | |
size | 'xs' | 'sm' | 'md' | Defines the size of each of the button in ButtonGroup | |
style | string | Enriched style to be provided to ButtonGroup | |
variant | 'primary' | 'secondary' | 'tertiary' | 'minimal' | Variant provided to Buttons. This prop is directly passed to the children. |
You can check the implementation of the component for more details.
ButtonGroup exports
You can import this module like so:
import {ButtonGroup} from 'spaceweb/button-group'
It exports the following components or utility functions:
- ButtonGroup
- StatefulButtonGroup