Skip to main content

Text

Text widgetText widget

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

NameDescriptionRequiredDefault
default()Initial value.No'' (empty)
complete()Ghost-text completion source: a list<string>, or a fn(array $answers): list<string>.NoNone

As you type, the first candidate your input is a case-insensitive prefix of appears dimmed after the caret; accept it with Tab or at the end of the line. This is distinct from the Suggest dropdown - ghost-text keeps your eye on the input line - and it is suppressed when colour is off.

Keyboard

KeyAction
printable keysInsert at the caret
/ Move the caret
BackspaceDelete the character before the caret
Tab / (at line end)Accept the ghost-text suggestion
EnterAccept
EscCancel

Display modes

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

ANSINo ANSI
UnicodeText: Unicode + ANSIText: Unicode + ANSIText: Unicode + No ANSIText: Unicode + No ANSI
ASCIIText: ASCII + ANSIText: ASCII + ANSIText: ASCII + No ANSIText: ASCII + No ANSI