wijjit.elements.input.select.Select
- class wijjit.elements.input.select.Select(id=None, classes=None, tab_index=None, options=None, value=None, values=None, multiple=False, width=20, visible_rows=5, disabled_values=None, placeholder='No options', on_change=None, border_style=None, title=None, bind=True)[source]
Select list element for choosing from a scrollable list of options.
This is a fixed-height scrollable list selector suitable for TUI applications. Unlike web dropdowns, this is always visible and uses vertical space efficiently.
- Parameters:
id (
str, optional) – Element identifieroptions (
list, optional) – List of options (strings or dicts with ‘value’ and ‘label’ keys)value (
str, optional) – Currently selected value (single-select mode)values (
list, optional) – List of selected values (multi-select mode)multiple (
bool, optional) – Enable multiple selection mode (default: False)width (
int, optional) – Display width for content area (default: 20). Note: Borders add 2 additional columns to total width when enabled.visible_rows (
int, optional) – Number of visible rows in the list (default: 5)disabled_values (
list, optional) – List of values that are disabled (cannot be selected)placeholder (
str, optional) – Text to display when options list is empty (default: “No options”)border_style (
BorderStyleor{"single", "double", "rounded"}orNone, optional) – Border style for the select list (default: None). - “single”: Single-line box-drawing characters - “double”: Double-line box-drawing characters - “rounded”: Rounded corner box-drawing characters - None: No borders (backward compatible) Can also accept BorderStyle enum values.title (
str, optional) – Title to display in the top border (only shown when border_style is not None)tab_index (int | None)
- Variables:
options (
list) – Available optionsmultiple (
bool) – Whether multiple selection is enabledvalue (
strorNone) – Currently selected value (single-select mode)selected_values (
set) – Set of selected values (multi-select mode)selected_index (
int) – Index of selected option (-1 if none, single-select mode)highlighted_index (
int) – Index of highlighted option for keyboard navigationwidth (
int) – Display width (content area, excluding borders)visible_rows (
int) – Number of visible rowsdisabled_values (
set) – Set of disabled valuesplaceholder (
str) – Text to display when options list is emptyscroll_manager (
ScrollManager) – Manages scrolling of options listborder_style (
BorderStyleorNone) – Border style for renderingtitle (
strorNone) – Title displayed in top border (when borders are enabled)
Notes
Options can be specified as: - Simple strings: [“Red”, “Green”, “Blue”] - Value/label dicts: [{“value”: “r”, “label”: “Red”}, …] - Mixed: [“Simple”, {“value”: “v”, “label”: “Complex”}]
Navigation: - Up/Down: Navigate options - Enter/Space: Select highlighted option (single) or toggle selection (multiple) - Home/End: Jump to first/last option - PageUp/PageDown: Scroll by page
- __init__(id=None, classes=None, tab_index=None, options=None, value=None, values=None, multiple=False, width=20, visible_rows=5, disabled_values=None, placeholder='No options', on_change=None, border_style=None, title=None, bind=True)[source]
Initialize scrollable element.
- Parameters:
id (
str, optional) – Element identifierclasses (
strorlistofstrorsetofstr, optional) – CSS class names for stylingtab_index (
int, optional) – Tab order for focus navigationvalue (str | None)
multiple (bool)
width (int)
visible_rows (int)
placeholder (str)
border_style (BorderStyle | Literal['single', 'double', 'rounded'] | None)
title (str | None)
Methods
__init__([id, classes, tab_index, options, ...])Initialize scrollable element.
add_class(class_name)Add a CSS class to this element.
apply_props(props)Apply props from a VNode, skipping ephemeral props.
can_scroll(direction)Check if the element can scroll in the given direction.
Get ephemeral state for reconciliation.
get_hardware_cursor_position()Absolute screen cell where the hardware terminal cursor should park.
get_height_for_width(width)Return the height this element needs when laid out at
width.get_intrinsic_size()Get the intrinsic (preferred) size of the element.
handle_key(key)Handle keyboard input.
handle_mouse(event)Handle mouse input.
has_class(class_name)Check if element has a CSS class.
on_blur()Called when element loses focus.
on_focus()Called when element gains focus.
on_hover_enter()Called when mouse enters element.
on_hover_exit()Called when mouse exits element.
on_mount()Called when element is first added to the element tree.
on_unmount()Called when element is removed from the element tree.
on_update(changed_props)Called when element props are updated during reconciliation.
remove_class(class_name)Remove a CSS class from this element.
render_signature()Hashable/comparable capture of everything
render_to()reads.render_to(ctx)Render the select element using cell-based rendering (NEW API).
restore_ephemeral_state(state)Restore ephemeral state after reconciliation.
set_bounds(bounds)Set the element's screen bounds.
toggle_class(class_name)Toggle a CSS class on this element.
Attributes
captures_tabWhether this element wants the Tab key instead of focus movement.
Get the state key for highlighted index.
Get the normalized options list.
parent_frameGet the parent Frame if this element is inside a scrollable frame.
Get the current scroll position.
scroll_state_keyGet the state key for vertical scroll position.
scroll_state_key_xGet the state key for horizontal scroll position.
supports_dynamic_sizingWhether this element supports dynamic sizing.
Get the selected values as a list.
- property highlight_state_key: str | None
Get the state key for highlighted index.
Returns the explicitly set key if provided, otherwise auto-generates from the element id using the convention “{id}:highlight”.
- on_focus()[source]
Called when element gains focus.
Note: highlighted_index is preserved across renders via state persistence, so we don’t reset it here. It’s initialized correctly during __init__ (either from state restoration or defaults to selected_index).
- Return type:
None
- property values: list[str]
Get the selected values as a list.
In single-select mode, returns a list with one element (or empty). In multi-select mode, returns all selected values.
- property scroll_position: int
Get the current scroll position.
- Returns:
Current scroll offset (0-based)
- Return type:
- handle_key(key)[source]
Handle keyboard input.
- Parameters:
key (
Key) – Key press to handle- Returns:
True if key was handled
- Return type:
- async handle_mouse(event)[source]
Handle mouse input.
- Parameters:
event (
MouseEvent) – Mouse event to handle- Returns:
True if event was handled
- Return type:
- render_to(ctx)[source]
Render the select element using cell-based rendering (NEW API).
- Parameters:
ctx (
PaintContext) – Paint context with buffer, style resolver, and bounds- Return type:
None
Notes
This is the new cell-based rendering method that uses theme styles instead of hardcoded ANSI colors. It renders a scrollable list of options with optional borders and title.
Theme styles:
This element uses the following theme style classes: -
select: Base select style -select:focus: Focused select style -select.border: Border style -select.border:focus: Focused border style -select.option: Option item style -select.option:selected: Selected option style (marked with an asterisk) -select.option:highlighted: Highlighted option style (keyboard focus) -select.option:disabled: Disabled option style -select.placeholder: Placeholder text style (empty state)