Text
Single-line text input with a movable caret. It collects a string.
$p->text('item', 'Item')
->default('Pear'); // Initial value.
// Inline ghost-text autocomplete over a static candidate list:
$p->text('item', 'Item')
->complete(['Pear', 'Peach', 'Plum']);
// The candidates can be computed from the answers collected so far
// (guard the lookup - a field may be unanswered when this runs):
$p->text('variety', 'Variety')
->complete(fn(array $answers): array => [($answers['fruit'] ?? 'Apple') . ' - Gala']);
Runnable script: playground/02-widgets-text.php.
Options
| Name | Description | Required | Default |
|---|---|---|---|
default() | Initial value. | No | '' (empty) |
complete() | Ghost-text completion source: a list<string>, or a fn(array $answers): list<string>. | No | None |
As you type, the first candidate that starts with your input (case-insensitively) appears dimmed after the caret; accept it with Tab or → at the end of the line. It's distinct from the Suggest dropdown - ghost text keeps your eye on the input line - and it's suppressed when color is off.
Keyboard
| Key | Action |
|---|---|
| printable keys | Insert at the caret |
| ← / → | Move the caret |
| Backspace | Delete the character before the caret |
| Tab / → (at line end) | Accept the ghost-text suggestion |
| Enter | Accept |
| Esc | Cancel |
Display modes
In all four display modes - Unicode or ASCII, color on or off:
| ANSI | No ANSI | |
| Unicode | ||
| ASCII |