Skip to content

ToggleButtonGroup ​

A ToggleButtonGroup is a group of ToggleButtons that allows users to select one or multiple buttons from the group.

NameValue
Props
disabled
View
Reading direction

Overview ​

When to use ToggleButtonGroup ​

Use the ToggleButtonGroup component when you require users to select either one or multiple options from a group. If you want users to choose from a set of actions, with the restriction that only one can be active at a time, use the ButtonGroup instead.

Use the ToggleButtonGroup to filter information on the screen or switch between views. To navigate between different sections of content on the page, use Tabs instead.

About ToggleButtonGroup ​

ToggleButtonGroup consists of a minimum of two ToggleButtons, which include the following elements.

Label ​

Each button within the ToggleButtonGroup must have a label. Button labels should be as short as possible, with text that clearly states what option will be selected when the button is toggled on.

  • Customize the content of each button, allowing for superscript, subscript, or special characters.
  • Use numbers instead of text if needed.

Icon (optional) ​

Icons simplify user recognition and provide the ability to shorten button labels to a minimum. In the case of icon-only buttons, the label will be available only to screen reader users.

  • Mix text-only and icon-only buttons exclusively when using the β€˜ellipsisβ€˜ icon to indicate additional actions.
  • In order to ensure consistency, avoid mixing different types of button contents within the same ButtonGroup.
  • Icon-only buttons may be used to form a ToggleButtonGroup but only if the icons used are universally understood and do not require accompanying text.

Examples ​

Single value ​

In this example, one button can be selected at a time.

Developer notes

To allow only a single value to be selected, initialize v-model to null. Open up the console to review emitted events.

Initially selected ​

The ToggleButtonGroup can have an initial selection.

Developer notes

To start with one button already selected, initialize v-model to that value.

Use the icon property to add an icon before the text of a button. Use the disabled property to disable individual buttons. For more information on how to control the appearance of each button, see the ButtonGroup documentation.

Multiple values ​

In this example, multiple buttons can be selected at a time.

Developer notes

To allow multiple values to be selected, initialize v-model to an empty array ([]). To start with some of buttons already selected, initialize v-model to an array of the values of those buttons. Open up the console to review emitted events.

Disabled ​

You can disable the entire ToggleButtonGroup or individual buttons.

Developer notes

The entire component can be disabled by setting the disabled prop. Individual buttons can be disabled by setting their disabled property.

Overflowing buttons ​

When the button group is too large to fit on one line, the buttons overflow to the next line.

Custom button display ​

The contents of the buttons can be customized using the default slot.

Developer notes

The ButtonGroupItem object for each button is available through the button binding, and the selected state of each button is available through the selected binding. In this example, the value of the button is displayed after its label, but only if the button is selected.

Technical implementation ​

Vue usage ​

Whether the group is single-select or multi-select is automatically detected based on the value bound to v-model: if it's an array, the group allows multiple selections; otherwise, it only allows a single selection. To initially select nothing, initialize the v-model value to null (for single-select groups) or [] (for multi-select groups).

Props ​

Prop nameDescriptionTypeDefault
buttons(required)Buttons to display. See the ButtonGroupItem type.ButtonGroupItem[]
modelValue(required)Selected value, or array of selected values.

If this is a string or number, the button whose value equals that string or number is selected, and only a single selection is allowed. If this is an array, the buttons whose values equal any of the values in the array are selected, and multiple selections are allowed. To select none of the buttons initially, set this to null (for single-selection groups) or to [] (for multi-selection groups).

Must be bound with v-model.
(string|number)[]
disabledWhether the entire group is disabled.

If this is set to true, all buttons in the group are disabled. Buttons can also be disabled individually by setting their disabled property to true.
booleanfalse

Events ​

Event namePropertiesDescription
update:modelValuemodelValue (string|number)[] - The new model valueEmitted when modelValue changes.

Slots ​

NameDescriptionBindings
defaultContent of an individual buttonbutton ButtonGroupItem - Object describing the button to display
selected boolean - Whether the button is selected

Keyboard navigation ​

KeyFunction
TabIt moves the focus to the next button within the group or to the next interactive element in tab order when the focus is placed on the last button of the group.
Shift + TabIt moves the focus to the previous button within the group or to the previous interactive element when the focus is placed on the first button of the group.
Enter / SpaceIf the focus is placed on one of the ToggleButtons within the group, it toggles that button on and off.