Skip to content

Select

final class Phui\Components\Select

A trigger showing the chosen label, which opens a floating list where one option is picked. The trigger takes focus; opening it raises a modal layer anchored beneath, which holds focus while open and hands it back on close.

selected is an index into items, or null for nothing chosen.

An open select with one option chosen and another hovered

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

Select::mount()
    ->props(items: $this->branches, selected: $this->branch)
    ->on('change', fn (EmitEvent $e) => $this->branch = $e->data);

Props

PropTypeDefaultDescription
itemsstring[][]The options to list.
placeholderstring'Select…'Shown on the trigger while nothing is selected.
maxHeightint10Options visible before the list scrolls.
accentstring'|'The marker at the head of the trigger.
selectedCharstring'✓'Marker beside the chosen option.
unselectedCharstring' 'Marker beside every other option.
hoveredCharstring'→'Marker beside the option under the cursor.
unhoveredCharstring' 'Marker beside every other option.

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
selected?intnullchange

Emits

EventPayloadEmitted when
changeintAn option is chosen.

Input

InputAction
EnterOpen the list
Left clickOpen the list

While the list is open:

InputAction
kPrevious option
jNext option
Enter SpaceChoose the option and close
EscClose without choosing
Left clickChoose the clicked option and close

Colours

Phui\Components\Colours\SelectColours

ColourPalette defaultUsed for
valuetextThe trigger label at rest.
valueFocusedaccentThe trigger label while focused.
markermutedThe trigger accent with nothing selected, and unchosen option markers.
markerActiveaccentThe trigger accent with a selection, the chosen option's marker, and the list border.
optiontextOptions in the list.
optionHighlightedaccentThe option under the cursor.

Released under the MIT License.