Skip to content
Back

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-control
MCP
Dioxus
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),
    }
}

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.

Terminal
cargo install --git https://github.com/ismailqureshi72/Oxyn oxyn-cli
oxyn init
oxyn add segmented-control
Rust
use 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

Dioxus · rust
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

PropTypeDefaultDescription
optionsrequiredVec<Segment>—Options.
valueOption<String>Default::default()Selected value (default: first enabled option).
sizeString"md"`sm` · `md` · `lg`.
variantString"tray"`tray` · `underline`.
kindString"radio"`radio` · `tabs`.
full_widthboolDefault::default()Stretch to the container.
verticalboolDefault::default()Vertical.
disabledboolDefault::default()Disabled.
draggablebooltrueDrag the pill across.
aria_labelString"Options"Accessible name.
on_changeEventHandler<String>—Changed.
on_option_intentEventHandler<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

KeyAction
←or→Move and select (↑ / ↓ when vertical)
HomeorEndFirst / last option
DragDrag 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::indicator computes 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
TransitionDurationEasingNotes
Glide (trailing edge)280 msease.out
Leading edge280 ms × 0.65ease.outthe stretch
Weight crossfade180 msease.out
Count blur-in180 msease.out
Press80 ms, 0.97ease.out
Reduced motionpill 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 SegmentedControl from oxyn_dioxus and include PRIMITIVES_CSS plus the token stylesheet once.
  • A GPUI version exists: SegmentedEl in oxyn_gpui.
  • Props to set first: options.
  • 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