Add search to Textual's SelectionList.
- Selectable items can be filtered by substring.
- Select one or multiple items.
- Search is case-insensitive.
- Title and description can be customized.
pip install textual-searchable-selectionlistfrom textual_searchable_selectionlist.options import SelectionStrategy
from textual_searchable_selectionlist.select import select, select_enum
selected = select(
['John', 'Jane', 'James'],
selection_strategy=SelectionStrategy.MULTIPLE,
search_title='Select people',
)
# Enums
# class Color(Enum):
# RED = 'red'
# GREEN = 'green'
#
# selected_colors = select_enum(Color, selection_strategy=SelectionStrategy.ONE)Use selected_callback when embedding the widget, or listen for the
SearchableListWidget.Selected message in your app.
from textual.app import App, ComposeResult
from textual_searchable_selectionlist.options import SelectionStrategy
from textual_searchable_selectionlist.searchable_list_widget import SearchableListWidget
class MyApp(App):
def compose(self) -> ComposeResult:
yield SearchableListWidget(
"Alpha",
"Beta",
"Gamma",
selection_strategy=SelectionStrategy.ONE,
selected_callback=self._on_selected_callback,
)
def _on_selected_callback(self, selected: list[str]):
self.log(f"Callback selected: {selected}")
def on_searchable_list_widget_selected(
self, event: SearchableListWidget.Selected
):
self.log(f"Event selected: {event.selected}")Make sure uv is installed globally.
There are currently no automated tests. Manual testing can be done by running:
python tests/manual/searchable_selection_list_select.py