Skip to content

ItemList ​

final class Phui\Components\ItemList

A virtualised list of lines with one of them selected. Only the rows in view are built, so the list stays cheap however many items it holds, and the selection is kept scrolled into view. Takes focus.

A file list with the third row selected and a scrollbar

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

ItemList::mount()
    ->props(items: $this->files, selected: $this->cursor, maxHeight: 12)
    ->on('change', fn (EmitEvent $e) => $this->cursor = $e->data);

Props ​

PropTypeDefaultDescription
itemsarray<int, string|StyledString>[]The lines to render.
maxHeightint10Rows visible before the list scrolls.
selectedCharstring'→'Marker beside the selected row.
unselectedCharstring' 'Marker beside every other row.

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
selectedint0change

Emits ​

EventPayloadEmitted when
changeintThe selected index moves.

Input ​

InputAction
↑ kPrevious item
↓ jNext item
Left clickSelect the clicked row

Movement stops at the first and last item rather than wrapping, and the selected row only takes its highlight colour while the list holds focus.

Colours ​

Phui\Components\Colours\ItemListColours

ColourPalette defaultUsed for
itemtextUnselected rows, and the selected row while unfocused.
itemSelectedaccentThe selected row while focused.
markermutedThe marker beside unselected rows.
markerSelectedaccentThe marker beside the selected row.
scrollThumbaccentThe scrollbar thumb.

Released under the MIT License.