-
Notifications
You must be signed in to change notification settings - Fork 9
Component SplitButton
MeowLynxSea edited this page Jun 13, 2026
·
4 revisions
A primary action button with a chevron that opens a dropdown of secondary actions. The chevron shares the primary button's look but routes to a DropdownMenu of items.
use yororen_ui::headless::split_button::split_button;
use yororen_ui::headless::dropdown_menu::DropdownMenuItem;
use yororen_ui::headless::dropdown_menu::DropdownMenuState;use yororen_ui::headless::split_button::split_button;
use yororen_ui::headless::dropdown_menu::DropdownMenuItem;
use gpui::Entity;
let menu_state: Entity<DropdownMenuState> = cx.new(|cx| DropdownMenuState::new(cx));
split_button(
"run-action",
|_event, _window, _cx| { /* primary action */ },
cx,
)
.caption("Run")
.items(vec![
DropdownMenuItem::new("run-debug", "Run with debugger"),
DropdownMenuItem::new("run-profile", "Run with profiler"),
])
.state(menu_state)
.on_select({
let entity = cx.entity();
move |id: SharedString, _window, cx| {
entity.update(cx, |s, _cx| s.last_action = id);
}
})
.render(cx)| Method | Purpose |
|---|---|
disabled(v) |
Disable both halves of the button. |
caption(text) |
Primary label (e.g. "Run"). |
items(v) |
The Vec<DropdownItem> shown in the dropdown half. |
on_select(closure) |
Fn(SharedString, &mut Window, &mut App) + 'static + Send + Sync. The id of the picked item. |
state(s) |
An Entity<DropdownMenuState> the caller owns. |
The primary click is supplied to the factory as the second argument: Fn(&ClickEvent, &mut Window, &mut App) + 'static + Send + Sync.
- Factory takes
(id, primary, cx). Thecxis needed for the focus handles (primary + chevron each get their own). - The
state: Entity<DropdownMenuState>is optional — without it, the chevron still opens a dropdown but the caller cannot programmatically toggle it. Pass one if you want to read the open state or close it from the outside. -
.render(cx)returnsStateful<Div>.
Button, DropdownMenu, ToggleButton
Yororen UI v0.3.0 · repository · Apache-2.0 · This wiki documents Yororen UI v0.3.0.
This wiki documents Yororen UI v0.3.0 — the headless-core, swappable-renderer build.