Skip to main content

Module combo_box

Module combo_box 

Source
Expand description

ComboBox — dropdown selection widget.

Generic over the item type T: Clone + PartialEq + 'static. Selection is value-based: the bound Signal<Option<T>> survives reorder and insertion of the backing model. Items come from one of four input paths:

The dropdown panel’s node is created during build() and kept dormant, but its subtree is deferred — built the first time the combo is opened.

§Keyboard

The keys move a highlight through the list, and only a commit changes the value: the W3C ARIA select-only combobox pattern. A reader arrowing to hear the options changes nothing, and an application acting on the value (a language switcher) acts once, on the option the user picked.

  • Enter / Space: open the list; in the open list, commit the highlighted option and close.
  • ArrowDown / ArrowUp: open the list and move the highlight one item from the value, stopping at the ends; with no value, ArrowDown reaches the first item. Win32’s combo box, QComboBox, GTK and the W3C ARIA listbox pattern all stop rather than wrap; a combo box is a value, and wrapping is the menu convention.
  • Alt+ArrowDown / Alt+ArrowUp: open the list on the value (or the first item) without moving, and close it. The Win32 / WinForms / WPF chord and the ARIA combobox pattern.
  • F4: toggle the list (Win32 / Qt / WPF).
  • Escape: close the list and keep the value.
  • Home / End: first / last item.
  • PageUp / PageDown: one page, where a page is max_visible_items rows.
  • Printable characters: type-ahead, within type_ahead_timeout.
  • A chord holding Ctrl, Alt or Super is not the combo box’s and falls through to the application; Shift is, so a capital letter still types.

Every key that moves the highlight opens the list first when it is closed, so the reader hears the option it reaches. Focus stays on the combo box (or, in a searchable list, on its search field), which names the highlighted option as its active_descendant: every platform adapter follows that as the focus.

The widget is split across four internal modules:

  • state holds the ItemSource accessor, the default max_visible_items constant, and the index helpers.
  • item holds the single-row DropdownItem widget.
  • panel holds the DropdownPanel overlay content and the FilteredItemList inner widget.
  • tests holds the headless unit tests.

§Touch and pen

The closed box is one target — the arrow column is paint inside it, not a second target — and it opens the dropdown from its tap, so already on the release. The field’s hover tint is decoration with nothing behind it.

The dropdown’s rows are menu rows and take the menu row’s target floor at every density; before this they measured against the raw Compact constant while a MenuList’s rows grew, and the panel that shows max_visible_items of them now resolves the same number they do.

Structs§

ComboBox
A dropdown selection widget.

Enums§

ComboBoxVariant
Tier-1 design-language variant for a combo box trigger. Mirrors the TextInputVariant shape because both controls live in the same “form-field” visual family — apps that ship a Material 3 theme typically want filled triggers for both, etc.