Button Group
Anatomy
Groups multiple buttons with shared borders and optional interactive toggle behavior (exclusive or multiple selection).
maud_ui::primitives::button_group
Props
Generated from public Rust fields. Defaults are evaluated from the implementation.
| Prop | Type | Default | Description |
|---|---|---|---|
children | Markup | PreEscaped("") | No description |
orientation | Orientation | Horizontal | No description |
size | Option<String> | None | No description |
mode | Option<Mode> | None | When Some, the group opts into the bundled data-mui="button-group" behaviour that toggles aria-pressed on child buttons. |
Examples
Text alignment toolbar
Editor toolbar — exactly one alignment active at a time. Click or use ← / → to switch.
Text formatting
Rich-text controls — each toggle independent (Bold currently on). Click any to flip.
View switcher
Project listing view — Grid / List / Board (Grid active).
Pager with separator
Sm-size pager — [Prev] [separator] [Next]. The separator is a vertical rule between buttons in a horizontal group.
Pager with text indicator
Non-interactive text cell — [Page 1 of 10] [Prev] [Next]. Useful for status read-outs inside toolbars.
Usage and composition
Import
use maud_ui::primitives::button_group::{self, Orientation, Mode, Props};
Example
use maud::html;
use maud_ui::primitives::button_group;
html! {
(button_group::render(button_group::Props {
children: html! {
button type="button" class="mui-btn mui-btn--outline" { "Left" }
button type="button" class="mui-btn mui-btn--outline" { "Center" }
button type="button" class="mui-btn mui-btn--outline" { "Right" }
},
orientation: button_group::Orientation::Horizontal,
size: None,
mode: Some(button_group::Mode::Exclusive),
}))
}
Variants / Enums
Orientation
Horizontal: buttons in a row (default)Vertical: buttons in a column
Mode
Exclusive: exactly one button pressed at a time (radio-button behavior)Multiple: each button toggles independently
Helper Functions
| Function | Signature | Purpose |
|---|---|---|
separator | fn(Orientation) -> Markup | Renders a visual rule between buttons |
separator_for_group | fn(Orientation) -> Markup | Convenience: renders separator opposite to group orientation |
text | fn(Markup) -> Markup | Renders non-interactive text cell (e.g., page indicator) |
Related
Button, Dialog (for trigger dialogs inside button groups)
Shadcn reference
https://ui.shadcn.com/docs/components/base/button-group
Accessibility
Emits role="group" on the container. For vertical groups, includes aria-orientation="vertical". In interactive modes (Exclusive, Multiple), emits data-mui="button-group" and data-mode="exclusive|multiple" for JS to wire aria-pressed state changes. Emits custom mui:button-group-change event on activation with { value, pressed, target } in detail.