Raxol.UI.Components.Input.SelectList.Utils (Raxol v2.6.0)

View Source

Shared utility functions for SelectList component modules. Eliminates code duplication between Navigation and Selection modules.

Summary

Functions

Ensures that the selected item is visible within the scroll viewport. Adjusts scroll_offset to bring the selected item into view.

Filters options by a search query (case-insensitive substring match). Returns all options when query is empty.

Gets the effective options based on current filter/search state. Returns filtered_options if present, otherwise the full options list.

Extracts a display label from a SelectList option. Handles strings, tuples, and maps with :label, :text, :name, or :value keys.

Functions

ensure_visible(state)

Ensures that the selected item is visible within the scroll viewport. Adjusts scroll_offset to bring the selected item into view.

filter_options(options, query)

@spec filter_options([term()], String.t()) :: [term()]

Filters options by a search query (case-insensitive substring match). Returns all options when query is empty.

get_effective_options(state)

@spec get_effective_options(Raxol.UI.Components.Input.SelectList.t()) :: list()

Gets the effective options based on current filter/search state. Returns filtered_options if present, otherwise the full options list.

get_option_label(option)

@spec get_option_label(term()) :: String.t()

Extracts a display label from a SelectList option. Handles strings, tuples, and maps with :label, :text, :name, or :value keys.