Button group
Joined buttons for a toolbar: outline or solid, horizontal or vertical, icon-only with tooltips, a toggle selection and an overflow menu.
oxyn add button-groupDioxus
let items = vec![
GroupItem::new("bold", "Bold", Some("text")),
GroupItem::new("link", "Link", Some("link")),
GroupItem::new("code", "Code", Some("code")),
];
rsx! {
ButtonGroup {
items: items,
max_visible: None,
on_action: move |id: String| format(id),
}
}Rendered from Rust at build time · goes live when visible
When to use
- Agent UIs keep several related actions in a small space: the answer toolbar (copy, regenerate, good / bad, share), merge options on a PR card, formatting in an editor, model choice next to Run.
- Groups make them one object with one highlight, so the pointer reads as a single soft shape moving over the row instead of buttons flickering on and off.
When not to use
- Actions and choices behind any trigger: use Dropdown Menu instead.
- Switch between two to six options: use Segmented Control instead.
- A small label for one control: use Tooltip instead.
Installation
Button group is free and MIT. The oxyn CLI copies its code, and the components it needs, into src/oxyn/ of your Dioxus or GPUI project, so it is yours to change.
Terminal
cargo install --git https://github.com/ismailqureshi72/Oxyn oxyn-cli
oxyn init
oxyn add button-groupRust
use crate::oxyn::{ButtonGroup, PRIMITIVES_CSS};Rather depend on the crate? cargo add oxyn-dioxus oxyn-core --git https://github.com/ismailqureshi72/Oxyn, then use oxyn_dioxus::{ButtonGroup, PRIMITIVES_CSS};
Usage
Dioxus · rust
let items = vec![
GroupItem::new("bold", "Bold", Some("text")),
GroupItem::new("link", "Link", Some("link")),
GroupItem::new("code", "Code", Some("code")),
];
rsx! {
ButtonGroup {
items: items,
max_visible: None,
on_action: move |id: String| format(id),
}
}Examples
Outline
Default toolbar group.
Code
let items = vec![
GroupItem::new("bold", "Bold", Some("text")),
GroupItem::new("link", "Link", Some("link")),
GroupItem::new("code", "Code", Some("code")),
];
rsx! {
ButtonGroup {
items: items,
max_visible: None,
on_action: move |id: String| format(id),
}
}Solid toggle
Solid, icon-only, one selected.
Code
let items = vec![
GroupItem::new("bold", "Bold", Some("text")),
GroupItem::new("link", "Link", Some("link")),
GroupItem::new("code", "Code", Some("code")),
];
rsx! {
ButtonGroup {
items: items,
variant: "solid",
collapse_labels: true,
selected: "code",
max_visible: None,
on_action: move |id: String| format(id),
}
}Overflow
Six actions, four visible, the rest in a menu.
Code
let items = vec![
GroupItem::new("bold", "Bold", Some("text")),
GroupItem::new("link", "Link", Some("link")),
GroupItem::new("code", "Code", Some("code")),
];
rsx! {
ButtonGroup {
items: items,
size: "sm",
max_visible: Some(4),
on_action: move |id: String| format(id),
}
}Vertical
Stacked for a side rail.
Code
let items = vec![
GroupItem::new("bold", "Bold", Some("text")),
GroupItem::new("link", "Link", Some("link")),
GroupItem::new("code", "Code", Some("code")),
];
rsx! {
ButtonGroup {
items: items,
size: "sm",
vertical: true,
max_visible: None,
on_action: move |id: String| format(id),
}
}API reference
ButtonGroup
| Prop | Type | Default | Description |
|---|---|---|---|
itemsrequired | Vec<GroupItem> | — | Segments. |
variant | String | "outline" | `outline` · `solid`. |
size | String | "md" | `ide` (24) · `sm` (28) · `md` (32). |
vertical | bool | Default::default() | Vertical. |
collapse_labels | bool | Default::default() | Icons only (labels become tooltips). |
selected | Option<String> | Default::default() | Selected segment (toggle groups). |
max_visible | Option<usize> | Default::default() | Segments that fit before the rest go to an overflow menu. |
menu | Vec<MenuItem> | Default::default() | Attached menu at the end of the row. |
disabled | bool | Default::default() | Disabled. |
highlight | Option<usize> | Default::default() | Review sheets: force the highlight on a segment. |
on_action | EventHandler<String> | — | A segment or menu item ran. |
Read from the Rust signature and doc comments.
Keyboard interactions
| Key | Action |
|---|---|
| Tab | Each button is a tab stop |
| ↓or↑ on overflow | Open the overflow menu |
Accessibility
- role=group with a label; toggle groups expose aria-pressed per button.
- Icon-only buttons keep their labels as aria-label and tooltips.
From the spec
- Group:
role=group(toolbars:role=toolbar) witharia-orientation; one tab stop, arrow keys inside. Icon-only segments carryaria-labeland a tooltip. - Toggle segments expose
aria-pressed. The overflow trigger isaria-haspopup=menu+aria-expanded. - Split: the ▾ is a separate button named "More actions"; Esc returns focus to it.
- Expanding: every button is named by its label even while collapsed; the done label is announced once through a polite live region.
Motion & interaction
- One highlight lives under all segments (Arc): moving the pointer carries it on
spring.snap; keyboard moves jump. Appearing from nothing it grows in from 94 % instead of sliding from where it last was. The dividers next to it fade so it reads as one shape inside the joined surface. - Pressed segment answers in place (scale 0.96) without moving the highlight.
- Split button: the main half's label and icon morph in place while its width springs; the ▾ half never scales, so the menu opens from a still anchor; menu rows fade in with a 20 ms stagger. The chevron turns half a circle while open.
- Expanding: width springs between icon size and icon + measured label (Arc
morph, 420 ms); the label fades in after the width starts; confirmation swaps the icon for a check.
Timing
| Transition | Duration | Delay | Easing / spring | Stagger |
|---|---|---|---|---|
| Highlight glide | 214 ms (spring.snap) | 0 | spring | — |
| Highlight appear | 214 ms, scale 0.94 → 1, fade | 0 | ease.out | — |
| Divider fade | 120 ms | 0 | ease.out | — |
| Segment press | 80 ms, 0.96 | 0 | ease.out | — |
| Split label morph | 180 ms crossfade + width spring.snap | 0 | ease.out | — |
| Split menu open | 180 ms fade (anchor still) | 0 | ease.out | rows 20 ms |
| Floating tooltip | instant within the group (neighbour rule) | 0 | — | — |
| Auto-hide | 300 ms fade to 35 % | 3 s idle | ease.out | — |
| Expand width | 420 ms (Arc morph) | delay_ms (Oxyn plus, default 0) | ease.out | — |
| Confirm hold | 1400 ms (confirmDuration) | — | — | — |
| Reduced motion | highlight jumps (80 ms fade); no press scale; widths change in 80 ms; no stagger | — | linear | none |
Responsive behaviour
- max_visible moves the rest into an overflow menu instead of wrapping.
- ide size (24 px) is for dense editor toolbars.
Edge cases (spec)
- Disabled segments are skipped by arrows and never take the highlight.
- Highlight target removed (overflow recomputed): the highlight hides instead of pointing at nothing; the next hover makes it appear in place.
- Narrow containers:
fit()keeps as many segments as fit beside the overflow button. - Vertical groups: dividers become horizontal; arrows switch axis.
- Long done labels in the expanding group widen the reserved slot once, at mount.
- Touch: no hover; the floating group shows labels on long-press via the tooltip.
- Split button with one action renders the main half only (no menu).
Notes for AI
- Import
ButtonGroupfromoxyn_dioxusand includePRIMITIVES_CSSplus the token stylesheet once. - A GPUI version exists:
ButtonGroupElinoxyn_gpui. - Props to set first:
items. - Keep its states and timings as they ship; restyle it through the CSS variables rather than by hand.