Skip to main content

Select

Select widgetSelect widget

Single choice from a list of options. It collects the selected option value (a string).

$p->select('fruit', 'Fruit')
->options([
'apple' => 'Apple',
'banana' => 'Banana',
'cherry' => 'Cherry',
])
->default('banana') // Which option starts highlighted (defaults to the first).
->pageSize(10); // Options visible before the list pages around the cursor.

Runnable scripts: playground/02-widgets/select.php and select-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()Options shown before the list pages around the cursor.No10

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

Keyboard

KeyAction
/ Move the highlight (skips headings, separators and disabled options)
EnterAccept the highlighted option
EscCancel

Display modes

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

ANSINo ANSI
UnicodeSelect: Unicode + ANSISelect: Unicode + ANSISelect: Unicode + No ANSISelect: Unicode + No ANSI
ASCIISelect: ASCII + ANSISelect: ASCII + ANSISelect: ASCII + No ANSISelect: ASCII + No ANSI

Multiple selection

Add ->multiple() to collect a list<string> of checked values instead of one. Space toggles the highlighted option, typing narrows the list by substring, / select or deselect all visible, and Enter accepts the checked set.

$p->select('basket', 'Basket')
->multiple()
->options([
'apple' => 'Apple',
'carrot' => 'Carrot',
'tomato' => 'Tomato',
])
->default(['apple']); // Values pre-checked when the field opens.

Select widget in multiple modeSelect widget in multiple mode

ANSINo ANSI
UnicodeSelect (multiple): Unicode + ANSISelect (multiple): Unicode + ANSISelect (multiple): Unicode + No ANSISelect (multiple): Unicode + No ANSI
ASCIISelect (multiple): ASCII + ANSISelect (multiple): ASCII + ANSISelect (multiple): ASCII + No ANSISelect (multiple): ASCII + No ANSI