Skip to content

ToggleButtonGroup

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

Guidelines

Using toggle button groups

Buttons within the toggle button group must carry a label. In the case of icon-only buttons, the label will be available only to screen reader users.

Use the ToggleButtonGroup 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 simultaneously, use the ButtonGroup instead.

Specifications

Specification of ToggleButtonGroup.

A toggle button group consists of of a minimum of 2 toggle buttons, which may include the following elements:

  1. Icon (optional)
    Icons simplify user recognition and provide the ability to shorten button labels to a minimum.
  2. 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.
  3. White line
    For toggled-on buttons, a white line is added to visually separate them, whether they are on the same line or placed on different rows in the stacked version.

There is no maximum limit on the number of toggle buttons per group. The width of the ToggleButtonGroup will adjust to accommodate the expanding text within each button. If the total width surpasses the maximum width of max-width-button token (equivalent to 448px in the default Codex theme), the buttons will be arranged into the next row.

Maximum example for ToggleButtonGroup.

Refer to the ToggleButtonGroup component in Codex Figma.

Interaction states

ToggleButtonGroups have the following visually separate states:

Interaction states of ToggleButtonGroup, affecting the buttons within the group: default, hover, active, focus, selected, disabled, selected-hover, selected-active, selected-focus, two buttons selected, all buttons selected, and all buttons disabled.

  1. Default
  2. Hover on one button
  3. Active button
  4. Focus on one button
  5. One button is selected
  6. One button is disabled
  7. Hover on the selected button
  8. The selected button is active
  9. Focus on the selected button
  10. Two buttons are selected
  11. All buttons are selected
  12. All buttons are disabled

Best practices

Consider the following recommendations when working with toggle button groups.

Button’s content

Two ToggleButtonGroups: one using icons and the other using numbers instead of text.

Do:
  • Consider using text-only, text with icon, or icon-only buttons within the ToggleButtonGroup.
  • Use numbers instead of text within the buttons if appropriate.

ToggleButtonGroup using an icon just in one of the buttons.

Don't:
  • Mix different types of buttons within the same ToggleButtonGroup to maintain consistency.

Icon-only buttons

Icon-only ToggleButtonGroup using easy to recognize icons.

Do:
  • Use icon-only toggle buttons to create a ToggleButtonGroup if needed.
  • Ensure the icons used are universally recognizable and don't need accompanying text.

Icon-only ToggleButtonGroup using complex icons.

Don't:
  • Use icon-only buttons if the icons are unclear or don't effectively convey their purpose.

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 toggle buttons within the group, it toggles that button on and off.

Demos

Single value

To allow only a single value to be selected, initialize v-model to null.

Selected value: (null)

NameValue
View
Reading direction

Initially selected single value

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.

Selected value: framed

Multiple values

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.

Selected values: (none)

Disabled

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.

Selected values: (none)

Custom button display

The contents of the buttons can be customized using the default slot. 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.

Selected value: 2

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|null|( 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|( 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