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

Basic usage

Basic Intent usage

With icons

With enhancers

Radio mode

TopBar Button Group

Action Bar

Controlled Behaviour

Lorem ipsum dolor sit amet, ea insolens deseruisse mnesarchum mea. An munere utroque mentitum vis, ea rebum inani iudicabit has. Cu his dolorum perpetua. Mea atqui tation partem ne, ei vim etiam volumus nominavi. Cum id atqui cotidieque, quaeque nostrum salutandi cum at, idque scaevola platonem mei ad.
The Bold option has been selected 0 times

In radio mode, the button group functions similarly to a radio group. Only one button can be "selected" at a time.

Checkbox mode

In checkbox mode, the button group functions similarly to a group of checkboxes. Multiple buttons can be "selected" at the same time.

Disabled button group

You can disable the entire button group as in the example above. Or you can disable isolated buttons as in the example below.

Single disabled button

With a dropdown

Stateful (uncontrolled) with radio mode

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).

Stateful (uncontrolled) with checkbox mode

API

ButtonGroup props

NameTypeDefaultDescription
activateOnFocus
boolean
falseIndicates 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
falseIndicates 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