Skip to content
Back

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-group
MCP
Dioxus
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

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-group
Rust
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

PropTypeDefaultDescription
itemsrequiredVec<GroupItem>—Segments.
variantString"outline"`outline` · `solid`.
sizeString"md"`ide` (24) · `sm` (28) · `md` (32).
verticalboolDefault::default()Vertical.
collapse_labelsboolDefault::default()Icons only (labels become tooltips).
selectedOption<String>Default::default()Selected segment (toggle groups).
max_visibleOption<usize>Default::default()Segments that fit before the rest go to an overflow menu.
menuVec<MenuItem>Default::default()Attached menu at the end of the row.
disabledboolDefault::default()Disabled.
highlightOption<usize>Default::default()Review sheets: force the highlight on a segment.
on_actionEventHandler<String>—A segment or menu item ran.

Read from the Rust signature and doc comments.

Keyboard interactions

KeyAction
TabEach button is a tab stop
↓or↑ on overflowOpen 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) with aria-orientation; one tab stop, arrow keys inside. Icon-only segments carry aria-label and a tooltip.
  • Toggle segments expose aria-pressed. The overflow trigger is aria-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
TransitionDurationDelayEasing / springStagger
Highlight glide214 ms (spring.snap)0spring—
Highlight appear214 ms, scale 0.94 → 1, fade0ease.out—
Divider fade120 ms0ease.out—
Segment press80 ms, 0.960ease.out—
Split label morph180 ms crossfade + width spring.snap0ease.out—
Split menu open180 ms fade (anchor still)0ease.outrows 20 ms
Floating tooltipinstant within the group (neighbour rule)0——
Auto-hide300 ms fade to 35 %3 s idleease.out—
Expand width420 ms (Arc morph)delay_ms (Oxyn plus, default 0)ease.out—
Confirm hold1400 ms (confirmDuration)———
Reduced motionhighlight jumps (80 ms fade); no press scale; widths change in 80 ms; no stagger—linearnone

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 ButtonGroup from oxyn_dioxus and include PRIMITIVES_CSS plus the token stylesheet once.
  • A GPUI version exists: ButtonGroupEl in oxyn_gpui.
  • Props to set first: items.
  • Keep its states and timings as they ship; restyle it through the CSS variables rather than by hand.

Guides

Oxyn · 74 free components · 264 Pro components · 96 screens · 20 blocks · Dioxus and GPUI