Skip to content

TextArea

final class Phui\Components\TextArea

A multi-line editor with selection, word motions and clipboard support. Text soft-wraps at the measured width, the view is rows lines tall and scrolls vertically, and the cursor is always kept in view. Takes focus.

A multi-line editor holding wrapped text

php
use Phui\Components\TextArea;
use Phui\Events\EmitEvent;

TextArea::mount()
    ->props(value: $this->body, rows: 8, placeholder: 'Describe the change…')
    ->on('change', fn (EmitEvent $e) => $this->body = $e->data);

Props

PropTypeDefaultDescription
rowsint5Height of the view in lines.
maxCharsint50000Most characters the value may hold.
invalidboolfalseForces the invalid colour on.
placeholderstring'Type here...'Shown while the value is empty and the field is unfocused.
markerstring'│'The rule drawn down the left of every row.

Reaching maxChars shows the invalid colour, the same as setting invalid. Further typing and the overflow of a paste are dropped.

Models

The component holds this and emits on every change. Pass it as a prop to take ownership, and handle its emit — see binding a value both ways.

ModelTypeDefaultEmits
valuestring''change

Emits

EventPayloadEmitted when
changestringThe value is edited.

Input

InputAction
Any characterInsert at the cursor, replacing the selection
EnterInsert a newline
Move by one character
Move by one line, keeping the preferred column
Alt + Move by one word
Home EndMove to the start or end of the value
Shift + any motionExtend the selection instead of moving
BackspaceDelete back, or the selection
Alt + BackspaceDelete the word before the cursor
Delete Ctrl+dDelete forward, or the selection
Ctrl+aSelect all
Ctrl+yCopy the selection to the system clipboard
Ctrl+xCut the selection
Ctrl+wDelete the word before the cursor, or the selection
Ctrl+kDelete to the end of the line
Ctrl+uDelete to the start of the line
PasteInsert the pasted text, replacing the selection
Left clickMove the cursor to the clicked position
Scroll wheelScroll the view

Word motions treat spaces and newlines as boundaries.

Colours

Phui\Components\Colours\TextAreaColours

ColourPalette defaultUsed for
markermutedThe left rule at rest.
activeaccentThe left rule and cursor while focused, and the scrollbar thumb.
invaliddangerThe left rule and cursor while invalid.
placeholdermutedThe placeholder text.
selectionsurfaceThe background behind the selection.
scrollTracksurfaceThe scrollbar track.

The value itself is drawn in the terminal's default foreground; colour it by overriding marker and friends, or wrap the field to style around it.

Released under the MIT License.