Skip to main content

Search

Search widgetSearch widget

Single choice with a filter line above the options. Typing fuzzy-matches and ranks the labels - exact and prefix matches lead, looser subsequence matches follow - and highlights the matched characters. It collects the selected option value (a string).

$p->search('vegetable', 'Vegetable')
->options([
'carrot' => 'Carrot',
'potato' => 'Potato',
'onion' => 'Onion',
'pepper' => 'Pepper',
])
->default('carrot') // Which option starts highlighted.
->pageSize(8); // Matches visible before the list pages around the cursor.

Runnable scripts: playground/02-widgets/search.php and search-multiple.php.

Options

NameDescriptionRequiredDefault
options()The choices, as a value => label map (or added one at a time with option()).Yes-
default()Which option starts highlighted, by value.NoFirst option
pageSize()Matches shown before the list pages around the cursor.No10

For headings, separators and disabled options, see Option groups.

Keyboard

KeyAction
printable keysType to fuzzy-filter and rank the options
/ Move over the matches
BackspaceDelete a filter character
EnterAccept the highlighted option
EscCancel

Display modes

In all four display modes - Unicode or ASCII, colour on or off:

ANSINo ANSI
UnicodeSearch: Unicode + ANSISearch: Unicode + ANSISearch: Unicode + No ANSISearch: Unicode + No ANSI
ASCIISearch: ASCII + ANSISearch: ASCII + ANSISearch: ASCII + No ANSISearch: ASCII + No ANSI

Multiple selection

Add ->multiple() to collect a list<string> of checked values under the filter line. Typing fuzzy-matches and ranks with the matched characters highlighted, Space toggles, / select or deselect all visible, and Enter accepts the checked set.

$p->search('basket', 'Basket')
->multiple()
->options([
'apple' => 'Apple',
'banana' => 'Banana',
'carrot' => 'Carrot',
'tomato' => 'Tomato',
])
->default(['apple']);

Search widget in multiple modeSearch widget in multiple mode

ANSINo ANSI
UnicodeSearch (multiple): Unicode + ANSISearch (multiple): Unicode + ANSISearch (multiple): Unicode + No ANSISearch (multiple): Unicode + No ANSI
ASCIISearch (multiple): ASCII + ANSISearch (multiple): ASCII + ANSISearch (multiple): ASCII + No ANSISearch (multiple): ASCII + No ANSI