<iframe src="https://www.googletagmanager.com/ns.html?id=GTM-5HGSQD2L" height="0" width="0" style="display:none;visibility:hidden" title="GTM"></iframe>

Buttonbar

A set of closely related controls or actions, where selecting one applies it immediately.

Use Buttonbar...

  • To pick one choice from a linear set of closely related choices (such as β€œFront” and β€œBack”) and immediately apply that selection.
  • To select between 2-5 choices.
  • As a toggle control when the choices are not β€œon” or β€œoff”.

Don't use Buttonbar...

  • As a form of navigation.
  • To select more than 6+ choices, as this can be difficult to parse and take up too much horizontal space. Use a Dropdown or Listbox instead.
  • As a toggle control when the choices are β€œon” or β€œoff”. Use a Toggle Switch instead.

Width

Use width="full-width" to grow a Buttonbar to fill its container.

The preview has been updated.

Single-select

Use single-select when you want only one value to be selected at a time. The Buttonbar will act as a set of radio buttons.

The preview has been updated.

To set a default state:

  • In the React API, use defaultSelectedValue on the Buttonbar to specify an initial state.
  • In the Vanilla API, put a checked property onto the radio button that should be selected by default.

To control the state of the React API Buttonbar component, use the selectedValue and onSelectedValueChange props. onSelectedValueChangeΒ will be invoked with the new value as the first argument and the actualΒ <input>Β event as the second argument in case you need it.

The preview has been updated.

Multi-select

Use multi-select when you want to allow multiple options to be selected at the same time. The Buttonbar will act as a series of checkboxes.

The preview has been updated.

To set a default state:

  • In the React API, use defaultSelectedValues on the Buttonbar to specify an initial state.
  • In the Vanilla API, put a checked property onto the radio button that should be selected by default.

To control the state of the React API Buttonbar component, use the selectedValues and onSelectedValuesChange props. selectedValuesΒ is an array of selected values. onSelectedValuesChangeΒ will be invoked with an updated array of selected values as the first argument and the actualΒ <input>Β event as the second argument in case you need it.

The preview has been updated.

Toolbar

Use toolbar when you want to display a series of secondary Buttons.

The preview has been updated.

Disabled

Use disabled on ButtonbarButton when its option is unavailable.

The preview has been updated.

Implementation

  • A <fieldset>Β tag cannot be used because styling of that tag is not supported enough in Chrome.

Accessibility

  • Include an aria-label whose value is a localized description of what the buttonbar is or does, e.g. "Change view".
  • If the Buttonbar controls another section of the page, include an aria-controls attribute whose value is the id of the section it controls.

Props

Buttonbar
See core props for additional props that can be applied to this component.
proptyperequireddefault
aria-controls
Identifies the element (or elements) whose contents or presence are controlled by the current element. If the Buttonbar controls another section of the page, include an aria-controls attribute whose value is the id of the section it controls. @see aria-owns.
string
false
null
aria-label
Defines a string value that labels the current element. Provides a localized accessible label which describes what the buttonbar's purpose is. e.g. "Switch between the front and back of the business card" @see aria-labelledby.
string
false
null
variant
- `single-select` means using radio buttons, which are mutually exclusive - `multi-select` means using checkbox options, of which many can be selected at once - `toolbar` means using regular buttons
"toolbar""single-select""multi-select"null
false
single-select
width
The width of the buttonbar
"standard""full-width"null
false
standard
name
Name for the input element(ButtonbarButton)
stringnull
false
null
selectedValue
'value' of currently selected button. Used when controlling the state of the component
ButtonbarSelectedValue
false
null
defaultSelectedValue
The default selected value of the buttonbar. Used when not controlling the state of the component
ButtonbarSelectedValue
false
null
onSelectedValueChange
Callback fired when selected option is changed. `event` is the input's onChange event
((value: ButtonbarSelectedValue, event: ChangeEvent<HTMLInputElement, Element>) => void)null
false
null
selectedValues
List of 'values' of currently selected buttons.
ButtonbarSelectedValuesnull
false
null
defaultSelectedValues
By default selected buttons.
ButtonbarSelectedValuesnull
false
null
onSelectedValuesChange
Callback fired when one of the selections' value changes. It is passed the updated list of `selectedValues` and the actual `<input>` event in case you need it.
((selectedValues: ButtonbarSelectedValues, event: ChangeEvent<HTMLInputElement, Element>) => void)null
false
null
ButtonbarButton
See core props for additional props that can be applied to this component.
proptyperequireddefault
value
The value of the button
string
true
null

Related