Skip to content

Add ComboBox widget (searchable select)#6467

Open
steveanil wants to merge 1 commit intoTextualize:mainfrom
steveanil:feature/combo-box
Open

Add ComboBox widget (searchable select)#6467
steveanil wants to merge 1 commit intoTextualize:mainfrom
steveanil:feature/combo-box

Conversation

@steveanil
Copy link
Copy Markdown

@steveanil steveanil commented Apr 3, 2026

This PR is AI generated by Claude
Link to issue or discussion

#4167

cc @willmcgugan

What this adds

A ComboBox widget that combines a text Input with a filterable OptionList overlay — a standard "searchable select" / combobox pattern.

Design decisions

  • Focus stays on Input at all times. The parent ComboBox has can_focus=False. Arrow keys bubble up from Input and are proxied to the overlay, so the user can type and navigate without a focus ownership conflict.
  • Strict predefined-option selection. Free text that doesn't match an option is never accepted. Pressing Enter with no match reverts the input to the last valid selection (or clears it if nothing was ever selected).
  • Blur closes the overlay. When focus leaves the Input, the overlay collapses via a ComboBoxInput.LostFocus message.
  • ComboBox.Selected message is posted on selection, following the same pattern as Select.

Usage

yield ComboBox(
    [("Apple", 1), ("Banana", 2), ("Cherry", 3)],
    placeholder="Search...",
)

def on_combo_box_selected(self, event: ComboBox.Selected) -> None:
    print(event.value)

Files changed

File Purpose
src/textual/widgets/_combo_box.py Core implementation
src/textual/widgets/combo_box.py Public API re-export
src/textual/widgets/__init__.py Registers ComboBox in the widget namespace
src/textual/widgets/__init__.pyi Type stub
tests/test_combo_box.py 5 automated tests covering filtering, selection flow, blur, and no-match Enter behavior

Implements a ComboBox widget that combines a text Input with a
filterable OptionList overlay, addressing Textualize#4167.
@TomJGooding
Copy link
Copy Markdown
Collaborator

TomJGooding commented Apr 3, 2026

The Select widget already has type-to-search, so can you help explain exacttly what extra functionality this new widget provides? (Please don't just copy this question into Claude and paste its response)

@steveanil
Copy link
Copy Markdown
Author

The Select widget already has type-to-search, so can you help explain exacttly what extra functionality this new widget provides? (Please don't just copy this question into Claude and paste its response)

In the issue #4167, I was reading the details of the conversation and you mentioned that it should be a separate new widget that has a drop down list. This new widget filters the list itself as you type and the Select widget only lets you scroll through a fixed list.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants