Skip to content
GitHub11 stars

Button Group

A container that groups related buttons together with consistent styling.

<ButtonGroup>
    <ButtonGroup Class="hidden sm:flex">
        <Button Variant="ButtonVariant.Outline" Size="ButtonSize.Icon" aria-label="Go Back">

Installation

dnx Blazix.Cli add button-group

Usage

<ButtonGroup>
    <Button>Button 1</Button>
    <Button>Button 2</Button>
</ButtonGroup>

Composition

Use the following composition to build a ButtonGroup:

ButtonGroup
├── Button or Input
├── ButtonGroupSeparator
└── ButtonGroupText

Accessibility

  • The ButtonGroup component has the role attribute set to group.
  • Use Tab to navigate between the buttons in the group.
  • Use aria-label or aria-labelledby to label the button group.
<ButtonGroup aria-label="Button group">
    <Button>Button 1</Button>
    <Button>Button 2</Button>
</ButtonGroup>

ButtonGroup vs ToggleGroup

  • Use the ButtonGroup component when you want to group buttons that perform an action.
  • Use the ToggleGroup component when you want to group buttons that toggle a state.

Orientation

Set the Orientation parameter to change the button group layout.

<ButtonGroup Orientation="Orientation.Vertical" aria-label="Media controls" Class="h-fit">
    <Button Variant="ButtonVariant.Outline" Size="ButtonSize.Icon" aria-label="Increase"><Icon Data="LucideIcons.Plus" /></Button>
    <Button Variant="ButtonVariant.Outline" Size="ButtonSize.Icon" aria-label="Decrease"><Icon Data="LucideIcons.Minus" /></Button>
</ButtonGroup>

Size

Control the size of buttons using the size parameter on individual buttons.

<div class="flex flex-col items-start gap-8">
    <ButtonGroup>
        <Button Variant="ButtonVariant.Outline" Size="ButtonSize.Sm">Small</Button>

Nested

Nest <ButtonGroup> components to create button groups with spacing.

<ButtonGroup>
    <ButtonGroup>
        <Button Variant="ButtonVariant.Outline" Size="ButtonSize.Icon" aria-label="Add"><Icon Data="LucideIcons.Plus" /></Button>

Separator

The ButtonGroupSeparator component visually divides buttons within a group.

Buttons with variant outline do not need a separator since they have a border. For other variants, a separator is recommended to improve the visual hierarchy.

<ButtonGroup>
    <Button Variant="ButtonVariant.Secondary" Size="ButtonSize.Sm">Copy</Button>
    <ButtonGroupSeparator />
    <Button Variant="ButtonVariant.Secondary" Size="ButtonSize.Sm">Paste</Button>
</ButtonGroup>

Split

Create a split button group by adding two buttons separated by a ButtonGroupSeparator.

<ButtonGroup>
    <Button Variant="ButtonVariant.Secondary">Button</Button>
    <ButtonGroupSeparator />
    <Button Size="ButtonSize.Icon" Variant="ButtonVariant.Secondary" aria-label="Add"><Icon Data="LucideIcons.Plus" /></Button>
</ButtonGroup>

Input

Wrap an Input component with buttons.

<ButtonGroup>
    <Input placeholder="Search..." />
    <Button Variant="ButtonVariant.Outline" aria-label="Search"><Icon Data="LucideIcons.Search" /></Button>
</ButtonGroup>

Input Group

Wrap an InputGroup component to create complex input layouts.

<ButtonGroup Class="[--radius:9999rem]">
    <ButtonGroup>
        <Button Variant="ButtonVariant.Outline" Size="ButtonSize.Icon" aria-label="Add">

Create a split button group with a DropdownMenu component.

<ButtonGroup>
    <Button Variant="ButtonVariant.Outline">Follow</Button>
    <DropdownMenu>

Select

Pair with a Select component.

<ButtonGroup>
    <ButtonGroup>
        <Select Items="Currencies" @bind-Value="_currency">

Popover

Use with a Popover component.

<ButtonGroup>
    <Button Variant="ButtonVariant.Outline">
        <Icon Data="LucideIcons.Bot" />

RTL

To enable RTL support in Blazix, see the RTL configuration guide.

Translated with AI for the demo, so it may have mistakes.

<ButtonGroup>
    <ButtonGroup Class="hidden sm:flex">
        <Button Variant="ButtonVariant.Outline" Size="ButtonSize.Icon" aria-label="@T.GoBack">

API Reference

ButtonGroup

ParameterTypeDefault
Orientation Orientation? -
Class string? -
ChildContent RenderFragment? -

Other attributes are passed to the element it renders.

ButtonGroupSeparator

ParameterTypeDefault
Orientation Orientation Orientation.Vertical
Class string? -

Other attributes are passed to the element it renders.

ButtonGroupText

ParameterTypeDefault
Render RenderFragment<UseRenderProps>? -
Class string? -
ChildContent RenderFragment? -

Other attributes are passed to the element it renders.