Skip to main content

Toggle

Toggle widgetToggle widget

An inline switch that cycles between a fixed set of labelled values. It collects the selected option value (a string), and is always in one of its states, so it always returns a value.

$p->toggle('ripeness', 'Ripeness')
->options([
'ripe' => 'Ripe', // value => label
'unripe' => 'Unripe',
])
->default('ripe'); // Which value starts selected (defaults to the first).

Runnable script: playground/02-widgets/toggle.php.

Options

NameDescriptionRequiredDefault
options()The values to switch between, as a value => label map.Yes-
default()Which value starts selected.NoFirst option

Keyboard

KeyAction
/ / Space / / Cycle to the adjacent value
a letterJump to the first value whose label starts with it
EnterAccept the current value
EscCancel

Display modes

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

ANSINo ANSI
UnicodeToggle: Unicode + ANSIToggle: Unicode + ANSIToggle: Unicode + No ANSIToggle: Unicode + No ANSI
ASCIIToggle: ASCII + ANSIToggle: ASCII + ANSIToggle: ASCII + No ANSIToggle: ASCII + No ANSI