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.

Option descriptions

Give an option a description to explain what the choice implies. It shows as a secondary line beneath the list for the highlighted option and updates as the highlight moves. It is presentational only - the field still collects the selected value, never the description - it wraps to the available width, is dropped when the panel is too narrow to show it, and is absent from headless collection.

Option descriptions tracking the highlighted optionOption descriptions tracking the highlighted option

$p->select('fruit', 'Fruit')
->option('apple', 'Apple', description: 'Crisp and sweet, the everyday choice.')
->option('banana', 'Banana', description: 'Rich in potassium; ripens off the tree.')
->option('cherry', 'Cherry', description: 'Short season; best eaten fresh.');

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

ANSINo ANSI
UnicodeOption descriptions: Unicode + ANSIOption descriptions: Unicode + ANSIOption descriptions: Unicode + No ANSIOption descriptions: Unicode + No ANSI
ASCIIOption descriptions: ASCII + ANSIOption descriptions: ASCII + ANSIOption descriptions: ASCII + No ANSIOption descriptions: ASCII + No ANSI

Descriptions work the same on search, suggest and reorder. Runnable script: playground/02-widgets-select-descriptions.php.

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, color 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

Selection limits

Bound how many values a multiple field collects with ->minSelections() and ->maxSelections(). The active limit shows as a hint below the list, an out-of-range selection is rejected inline when you accept, and the same bounds are enforced in headless collection.

$p->select('basket', 'Basket')
->multiple()
->minSelections(2) // Reject fewer than two checked.
->maxSelections(3) // Reject more than three checked.
->options([
'apple' => 'Apple',
'carrot' => 'Carrot',
'tomato' => 'Tomato',
]);

Select in multiple mode with selection limitsSelect in multiple mode with selection limits

ANSINo ANSI
UnicodeSelection limits: Unicode + ANSISelection limits: Unicode + ANSISelection limits: Unicode + No ANSISelection limits: Unicode + No ANSI
ASCIISelection limits: ASCII + ANSISelection limits: ASCII + ANSISelection limits: ASCII + No ANSISelection limits: ASCII + No ANSI

Runnable script: playground/02-widgets-select-multiple-limited.php.