Collections

List Box

A list of options, nonselecting until a selection mode is set.

Rust
1use herogpui::components::list_box::{ListBox, ListBoxItem};

Usage

Labels use 14px text with 20px lines; descriptions and section headers use 12px text with 16px lines.

Rust
1use herogpui::prelude::{ListBox, ListBoxItem, SelectionMode};
2use gpui::prelude::*;
3use gpui::px;
4
5gpui::div()
6    .w(px(220.))
7    .child(ListBox::new(
8        "list-box",
9        vec![
10            ListBoxItem::new("inbox", "Inbox"),
11            ListBoxItem::new("sent", "Sent"),
12            ListBoxItem::new("drafts", "Drafts"),
13        ],
14    )
15    .selection_mode(SelectionMode::Single))

Live HeroGPUI compiled to WebAssembly. Select any example without loading another WASM instance.

Anatomy

Rust types

ListBoxListBoxItem

List Box is assembled from these builders. The API reference lists each one.

Customization

Appearance builders and theme tokens List Box uses.

Styling

List Box styling
StyleDescription
ListBox built-in text styles + Kbd::new().variant(Light)Built-in labels use 14px/20px medium text; descriptions and section headers use 12px/16px. Descriptions stack without a gap, and shortcuts reuse light Kbd.
relative + w_full + overflow_hidden + padding 4pxFull-width clipped list with four-pixel inset.
gap 4px in row geometryFour pixels between direct collection records without flex-shrinking virtual content.
FIELD_HEIGHT + gap(12) + soft_radius + px(8) + py(6)Option minimum height, 12px gap, 16px radius, and 8px/6px padding match.
anim::pressed(PRESSED_SCALE_SUBTLE)Pressed geometry matches; uses its shared press timeline rather than the exact quart curve.
colors.default.color hoverEnabled pointer hover uses the default surface fill.
inline trailing 16px indicatorSize and default/danger colors match; flex layout places it at the trailing edge without the absolute logical-end positioning.
ListBoxItemVariant::DangerDanger options and their indicator use the danger semantic color.
ListBoxItem::Section rowFlattens section heading records into the list rather than nesting a section container.
separator margin and widthSeparators are centered at 94% width.

API reference

Builders

List Box builders
BuilderTypeDefaultDescription
selection_mode(SelectionMode)SelectionModeSelectionMode::NoneChooses inert, single, or multiple selection semantics; the wrapper sets no default, so the one applies.
selected_keys(keys)SelectionControlled selected keys; the owner must accept reported changes.
default_selected_keys(keys)SelectionSeeds the list's uncontrolled selected-key set once.
on_selection_change(callback)Fn(keys: Selection) -> ()Reports the complete selected-key set after pointer and keyboard changes.
disabled_keys(keys)iterable of keysRemoves matching options from pointer and keyboard selection stops.
on_action(callback)Fn(key: Key) -> ()Reports item activation independently from selection where gives action priority.
variant(ListBoxItemVariant)ListBoxItemVariantListBoxItemVariant::DefaultDefault visual variant inherited by options unless an item overrides it.
disallow_empty_selection(bool)boolfalseInherited policy blocks the final-key toggle and Escape clearing.
should_focus_wrap(bool)boolfalseInherited policy joins the arrow-key ends.
entry focus onlybool | FocusStrategyfalseEntry focus follows the selected key or first enabled option, but automatic mount focus is not exposed.
escape_key_behavior(EscapeKeyBehavior)EscapeKeyBehaviorEscapeKeyBehavior::ClearSelectionControls whether unmodified Escape clears a nonempty selection or remains available to an enclosing interaction.
new(id, items)id, itemsItems, sections, and separators are supplied as the constructor collection.
new(key, label)key, labelStable option identity used for selection and callbacks.
is_disabled(bool)boolfalseDisables one option independently from disabledKeys.
item_content(render)AnyElement | render closureReplacement row content receives selected, focused, focus-visible, pressed, and disabled state.
indicator(render)AnyElement | render closurecheckmarkReplaces the selected indicator and receives isSelected.
section(label) / separator()label / AnyElementSection headers and separators are explicit collection records.
row_height(px)px48Fixed row geometry enables uniform-list virtualization; the virtual list caps at max_h, shrinks below it in a bounded parent, and pages by the visible viewport while skipping disabled stops.
estimated_row_height(px)pxEstimated variable row geometry enables measured list virtualization.
heading_height(px)px48Sets virtual section-row height.
gap(px)px0Overrides the direct-child spacing.
padding(px)px0Overrides the list inset.

Parts

List Box parts
PartDescription
ListBoxSelection, focus, keyboard, scrolling, and virtualization owner.
ListBoxItemSelectable option with label, description, icon, shortcut, variant, and render state.
ListBoxBuilt-in check or caller-rendered selected marker.
ListBoxItemNon-selectable heading record grouping following options; nested section ownership is flattened.

States

List Box states
BuilderStateDescription
selected_keys + indicatorSelectedSelection is shown by the trailing indicator without adding a row fill.
cursor keyed stateFocusedRoving keyboard cursor tracks one enabled option.
with_focus_ring + item_contentFocus visibleKeyboard focus draws the status ring and reaches item render state.
anim::pressed + interactionPressedInteractive options shrink to 98% and expose pressed render state.
row hover chromeHoveredEnabled options use the default hover fill; does not include hover in its documented item render-prop table.
is_disabled / disabled_keysDisabledDisabled options dim and leave pointer, arrow, typeahead, and selection stops.