Skip to content

MultiSelect

final class Phui\Components\MultiSelect

A trigger showing the chosen labels, which opens a floating list where several options can be ticked. The trigger takes focus; opening it raises a modal layer anchored beneath, which holds focus while open and hands it back on close.

selected holds indices into options, kept sorted and free of duplicates.

An open multi-select with two options ticked

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

MultiSelect::mount()
    ->props(
        options: ['Errors', 'Warnings', 'Notices'],
        selected: $this->levels,
        placeholder: 'All levels',
    )
    ->on('change', fn (EmitEvent $e) => $this->levels = $e->data);

Props

PropTypeDefaultDescription
optionsstring[][]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 a ticked option.
unselectedCharstring' 'Marker beside an unticked 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
selectedint[][]change

Emits

EventPayloadEmitted when
changeint[]An option is ticked or unticked.

Input

InputAction
EnterOpen the list
Left clickOpen the list

While the list is open:

InputAction
kPrevious option
jNext option
SpaceToggle option
EnterTick the option under the cursor, then close the list
EscClose the list, leaving the selection as it is
Left clickToggle the clicked option

Colours

Phui\Components\Colours\MultiSelectColours

ColourPalette defaultUsed for
valuetextThe trigger label at rest.
valueFocusedaccentThe trigger label while focused.
markermutedThe trigger accent with nothing selected, and unticked option markers.
markerActiveaccentThe trigger accent with a selection, ticked option markers, and the list border.
optiontextOptions in the list.
optionCursoraccentThe option under the cursor.

Released under the MIT License.