Segmented Control
Switch between two to six options: a raised pill or underline that glides and can be dragged across, with icons, counts and badges.
oxyn add segmented-controllet options = vec![
Segment::new("ask", "Ask"),
Segment::new("plan", "Plan"),
Segment::new("agent", "Agent"),
];
rsx! {
SegmentedControl {
options: options,
value: Some(mode()),
aria_label: "Mode",
on_change: move |m: String| mode.set(m),
}
}Rendered from Rust at build time · goes live when visible
When to use
- Switch between two to eight related views or modes in place: Ask / Plan / Agent, All / Running / Done, Diff / Files / Logs.
When not to use
- Switch the agent between Ask, Plan and Agent: use Mode switch instead.
- On or off for things that apply right away: use Switch instead.
- A main action with a menu of alternatives: use Split button instead.
Installation
Segmented Control 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.
cargo install --git https://github.com/ismailqureshi72/Oxyn oxyn-cli
oxyn init
oxyn add segmented-controluse crate::oxyn::{SegmentedControl, PRIMITIVES_CSS};Rather depend on the crate? cargo add oxyn-dioxus oxyn-core --git https://github.com/ismailqureshi72/Oxyn, then use oxyn_dioxus::{SegmentedControl, PRIMITIVES_CSS};
Usage
let options = vec![
Segment::new("ask", "Ask"),
Segment::new("plan", "Plan"),
Segment::new("agent", "Agent"),
];
rsx! {
SegmentedControl {
options: options,
value: Some(mode()),
aria_label: "Mode",
on_change: move |m: String| mode.set(m),
}
}Examples
Tray
Raised pill in a tray.
Code
let options = vec![
Segment::new("ask", "Ask"),
Segment::new("plan", "Plan"),
Segment::new("agent", "Agent"),
];
rsx! {
SegmentedControl {
options: options,
value: Some(mode()),
aria_label: "Mode",
on_change: move |m: String| mode.set(m),
}
}Underline tabs
Underline, tab semantics.
Code
let options = vec![
Segment::new("ask", "Ask"),
Segment::new("plan", "Plan"),
Segment::new("agent", "Agent"),
];
rsx! {
SegmentedControl {
options: options,
value: Some(mode()),
variant: "underline",
kind: "tabs",
aria_label: "Mode",
on_change: move |m: String| mode.set(m),
}
}Icons
Icons and a count.
Code
let options = vec![
Segment::new("ask", "Ask"),
Segment::new("plan", "Plan"),
Segment::new("agent", "Agent"),
];
rsx! {
SegmentedControl {
options: options,
value: Some(mode()),
size: "lg",
aria_label: "Mode",
on_change: move |m: String| mode.set(m),
}
}Six full width
Six options stretched.
Code
let options = vec![
Segment::new("ask", "Ask"),
Segment::new("plan", "Plan"),
Segment::new("agent", "Agent"),
];
rsx! {
SegmentedControl {
options: options,
value: Some(mode()),
size: "sm",
full_width: true,
aria_label: "Mode",
on_change: move |m: String| mode.set(m),
}
}API reference
SegmentedControl
| Prop | Type | Default | Description |
|---|---|---|---|
optionsrequired | Vec<Segment> | — | Options. |
value | Option<String> | Default::default() | Selected value (default: first enabled option). |
size | String | "md" | `sm` · `md` · `lg`. |
variant | String | "tray" | `tray` · `underline`. |
kind | String | "radio" | `radio` · `tabs`. |
full_width | bool | Default::default() | Stretch to the container. |
vertical | bool | Default::default() | Vertical. |
disabled | bool | Default::default() | Disabled. |
draggable | bool | true | Drag the pill across. |
aria_label | String | "Options" | Accessible name. |
on_change | EventHandler<String> | — | Changed. |
on_option_intent | EventHandler<String> | — | The: the pointer or focus reached a segment before it was chosen, so the host can start loading what it shows. |
Read from the Rust signature and doc comments.
Keyboard interactions
| Key | Action |
|---|---|
| ←or→ | Move and select (↑ / ↓ when vertical) |
| HomeorEnd | First / last option |
| Drag | Drag the pill across to choose |
Accessibility
- Roving tabindex; radio kind follows radio-group keys, tabs kind follows the WAI tabs pattern.
- Counts and badges are part of the option's name; the pill is aria-hidden.
From the spec
Roving tabindex; radio kind follows radio-group keys, tabs kind follows the WAI tabs pattern with manual activation. Counts and badges are part of the option's name. The pill is aria-hidden.
Motion & interaction
- The indicator glides to the picked option; the edge facing the target leads (35 % head Start), so it stretches a little and settles — calm, no bounce.
Segmented::indicatorcomputes both edges. - Labels crossfade regular → semibold while a hidden semibold copy holds the width, so neighbours never shift.
- When a label or count changes, the option and the control morph to the new width and the pill follows.
- Drag: the pill tracks the pointer 1:1 and drops onto the option under it.
Timing
| Transition | Duration | Easing | Notes |
|---|---|---|---|
| Glide (trailing edge) | 280 ms | ease.out | |
| Leading edge | 280 ms × 0.65 | ease.out | the stretch |
| Weight crossfade | 180 ms | ease.out | |
| Count blur-in | 180 ms | ease.out | |
| Press | 80 ms, 0.97 | ease.out | |
| Reduced motion | pill moves instantly; no stretch, no press scale; label weights swap | — | Arc |
Responsive behaviour
- full_width shares the width equally.
- Many options in a narrow panel: use full_width and sm; labels truncate before they wrap.
Edge cases (spec)
Eight options in a narrow panel: use full_width and sm; labels truncate before they wrap. Disabled current value (data changed): the pill stays but arrows skip to enabled options. Options added or removed: the indicator re-measures and jumps (no glide from a stale rect).
Notes for AI
- Import
SegmentedControlfromoxyn_dioxusand includePRIMITIVES_CSSplus the token stylesheet once. - A GPUI version exists:
SegmentedElinoxyn_gpui. - Props to set first:
options. - Keep its states and timings as they ship; restyle it through the CSS variables rather than by hand.