Selector
A trigger that opens an option list.
Try it
Interact with the control below. This preview runs the exact code sample shown on this page.
Basic use
use gpui::{Context};
use xgpui_luma_look_radix as radix;
use xgpui_luma::controls::selector::SelectorItem;
struct Example {
control: gpui::Entity<xgpui_luma::controls::selector::Selector>,
status: String,
}
impl Example {
fn new(cx: &mut Context<Self>) -> Self {
let control = radix::Selector::new("example")
.items([SelectorItem::new("draft").label("Draft"), SelectorItem::new("published").label("Published")])
.on_value_changed(cx, |app, item_id, _, cx| {
app.status = item_id.to_string();
cx.notify();
})
.spawn(cx);
Self { control, status: String::new() }
}
}Integration snippet, checked against the current SDK and Radix crates. cx is the initialized owner context. The control retains its callbacks; callback owners are held weakly. Render self.control.clone() in the owner’s view.
SDK behavior & customization
A popup dropdown, distinct from the always-visible Selection Panel.
Relevant contracts: SelectorRenderModel, SelectorTemplateModifier, SelectorTemplateHandlers, SelectorTemplate.
Use the module’s template contract for structural changes. Builder modifiers and item templates vary by control.
Events
Callbacks follow the existing SDK event stream. Registrations append, hold the owner weakly, and live until the control is released. cx.notify() requests an owner redraw. Compound payloads are borrowed; scalar values are passed by value.
| Event / payload | Callback |
|---|---|
Change { item_id: SharedString, label: SharedString } | .on_value_changed(cx, |app, item_id, label, cx| { … }) |
FocusChanged { focused: bool } | .on_focus_changed(cx, |app, focused, cx| { … }) |
OpenChanged { open: bool } | .on_open_changed(cx, |app, open, cx| { … }) |
Dismiss | .on_dismiss(cx, |app, cx| { … }) |
Use .on_event(cx, |app, event, cx| { … }) for all events. Factory-created controls support the same callbacks through SelectorEventExt. Existing cx.subscribe observers remain supported.