Select
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
| Name | Description | Required | Default |
|---|---|---|---|
options() | The choices, as a value => label map (or added one at a time with option()). | Yes | - |
default() | Which option starts highlighted, by value. | No | First option |
pageSize() | Options shown before the list pages around the cursor. | No | 10 |
For headings, separators and disabled options, see Option groups.
Keyboard
| Key | Action |
|---|---|
↑ / ↓ | Move the highlight (skips headings, separators and disabled options) |
Enter | Accept the highlighted option |
Esc | Cancel |
Display modes
In all four display modes - Unicode or ASCII, colour on or off:
| ANSI | No ANSI | |
| Unicode | ||
| ASCII |
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.
| ANSI | No ANSI | |
| Unicode | ||
| ASCII |