Blazor Button Group
The Blazor Bootstrap button group components join buttons into groups and toolbars, and turn sets of toggle buttons into radio and checkbox inputs. The examples below cover links, mixed styles, outlined styles, radio toggle buttons and checkbox toggle buttons.
INFO
The button group components follow the Bootstrap 5.3 button group.
ButtonGroup and ButtonToolbar lay out existing Button, Dropdown, and InputGroup components.
RadioButtonGroup and CheckboxButtonGroup are form inputs: they bind one value or a set of values, and work inside an EditForm.
WARNING
Every group and toolbar needs an accessible name. Set
AriaLabel, or set aria-labelledby to the id of a visible label. Without one, screen readers announce only "group" or "toolbar".
Basic usage #
Join a series of buttons on a single line.
How to use:
This demo picks a text alignment.
How to use:
- Add
ButtonGroupand placeButtoncomponents inside it. - Set
AriaLabelto describe what the buttons do together.
Links #
A group can join link buttons as well as buttons.
How to use:
This demo links to related demos; the current page is active.
How to use:
- Use
ButtonwithType="ButtonType.Link"andTo. - Mark the link to the current page with
Class="active"andaria-current="page".
Mixed styles #
Each button keeps its own color.
How to use:
This demo records a review decision.
How to use:
- Set a different
Coloron eachButton.
Outlined styles #
Outlined buttons join the same way.
How to use:
This demo shows text formatting buttons.
How to use:
- Set
Outline="true"on eachButton. - Give icon-only buttons an
aria-label.
Radio toggle buttons #
Pick one value from a set of toggle buttons.
How to use:
This demo picks a billing period and a chart range. The value type comes from the binding:
How to use:
- Add
RadioButtonGroupwith@bind-Valueand anAriaLabel. - Add one
ButtonGroupItemper choice, with itsValueandText(or child content). - Set
ColorandOutlineon the group for every button, or on an item to override it. - Set
Disabledon an item, or on the group to disable every item.
string and int here.
Checkbox toggle buttons #
Pick any number of values from a set of toggle buttons.
How to use:
This demo filters tasks by status, using an enum as the value type.
How to use:
- Add
CheckboxButtonGroupwith@bind-Valuesbound to anIEnumerable<TValue>property, and anAriaLabel. - Add one
ButtonGroupItemper choice.
Button toolbar #
Combine groups, and input groups, into a toolbar.
How to use:
This demo shows a pagination toolbar, an editor toolbar with an input group, and a table toolbar.
How to use:
- Add
ButtonToolbarwith anAriaLabel, and placeButtonGroupandInputGroupcomponents inside it. - Space the groups with margin utilities such as
Class="me-2", or spread them withClass="justify-content-between"on the toolbar.
Sizing #
Size every button in a group at once, nested groups included.
How to use:
This demo shows large, default, and small groups (the small one with a nested dropdown), and a large radio group.
How to use:
- Set
SizetoButtonGroupSize.SmallorButtonGroupSize.Largeon the group. - Do not size the individual buttons inside the group.
Nesting #
Put a dropdown inside a group.
How to use:
This demo shows message actions with a "More" menu.
How to use:
- Place a
DropdowninsideButtonGroup. - Set
Class="btn-group",role="group", and anaria-labelon theDropdown, so it joins the group as a nested group.
Vertical variation #
Stack the buttons vertically.
How to use:
This demo shows vertical buttons, a vertical group with a dropdown, and a vertical radio group.
How to use:
- Set
Vertical="true"onButtonGroup,RadioButtonGroup, orCheckboxButtonGroup. - Split button dropdowns are not supported in a vertical group, as in Bootstrap; use a regular dropdown.
EditForm validation #
Toggle button groups take part in an
How to use:
Submit the empty form to see both messages. Invalid groups get the
EditForm like other inputs.
How to use:
- Bind the group to a model property inside an
EditForm. - Add a
ValidationMessagefor the property after the group. - Name the group by its visible label with
aria-labelledby.
invalid class, and their inputs get aria-invalid="true".