gridlist

onChange called 0 time(s)

Shared with the studio
moodboard.png2.4 MB
invoice-april.pdf88 KB
sardines-on-toast.jpg1.1 MB

Picked: moodboard

Last button: nothing yet

import { computed, state } from '@markless/core';import { gridlist, lucide } from '@markless/ui';export default function Files() @{	let picked = state<readonly string[]>(['moodboard']);	let pressed = state('nothing yet');	const shown = computed(() => (picked.length === 0 ? 'nothing' : picked.join(', ')));	<div class="desk">		<gridlist.root			class="list"			selectable			value={picked}			onChange={(next: readonly string[]) => {				picked = next;			}}		>			<gridlist.label class="caption">Shared with the studio</gridlist.label>			<gridlist.item class="row" value="moodboard">				<gridlist.itemcontent class="cell">					<gridlist.itemindicator class="tick">						<lucide.check class="tick-icon" />					</gridlist.itemindicator>					<gridlist.itemlabel class="name">moodboard.png</gridlist.itemlabel>					<span class="size">2.4 MB</span>					<gridlist.itemtrigger						class="action"						onClick={() => {							pressed = 'Rename moodboard.png';						}}					>						Rename					</gridlist.itemtrigger>				</gridlist.itemcontent>			</gridlist.item>			<gridlist.item class="row" value="invoice">				<gridlist.itemcontent class="cell">					<gridlist.itemindicator class="tick">						<lucide.check class="tick-icon" />					</gridlist.itemindicator>					<gridlist.itemlabel class="name">invoice-april.pdf</gridlist.itemlabel>					<span class="size">88 KB</span>					<gridlist.itemtrigger						class="action"						onClick={() => {							pressed = 'Rename invoice-april.pdf';						}}					>						Rename					</gridlist.itemtrigger>				</gridlist.itemcontent>			</gridlist.item>			<gridlist.item class="row" value="sardines">				<gridlist.itemcontent class="cell">					<gridlist.itemindicator class="tick">						<lucide.check class="tick-icon" />					</gridlist.itemindicator>					<gridlist.itemlabel class="name">sardines-on-toast.jpg</gridlist.itemlabel>					<span class="size">1.1 MB</span>					<gridlist.itemtrigger						class="action"						onClick={() => {							pressed = 'Rename sardines-on-toast.jpg';						}}					>						Rename					</gridlist.itemtrigger>				</gridlist.itemcontent>			</gridlist.item>		</gridlist.root>		<p class="readout">			Picked: <span class="readout-value picked">{shown}</span>		</p>		<p class="readout">			Last button: <span class="readout-value pressed">{pressed}</span>		</p>	</div>;}

Click a row to pick it. Arrow to another row, then press Enter to reach its Rename button.

A gridlist is a list of rich rows, such as files or cards. Each row can hold its own buttons. Use it when each row needs controls of its own. For plain options, use select or combobox.

The whole list is one Tab stop. Arrow keys move focus from row to row. Enter moves focus into a row's buttons, and Escape brings it back out. When Tab returns to the list, focus lands on the row it left.

Each row has a name, its value. The root's value is the list of rows that are picked.

Anatomy

gridlist anatomy
Anatomy perspectiveFlat
Layers
Recent projects✓Brand studio12 filesWebsite
gridlist.root

A list of rich items - a card gallery, a file browser - where a row may hold controls of its own.

Pick more than one

Add multiple and several rows can be picked at once. multiple turns picking on by itself, so selectable is only for a list that picks one row at a time.

<gridlist.root multiple value={['moodboard', 'invoice']} onChange={keep}>

A click on a row picks it, and a second click lets it go. A click on a button inside a row does not pick the row. With multiple, Shift and a click picks every row from the last picked row to this one.

The arrow keys follow where rows sit on screen, not the order you wrote them. So cards in a wrapping layout move the way they look: Down goes to the card below. Add wrap and a walk off the last row comes back to the first.

<gridlist.root wrap style="display: flex; flex-wrap: wrap; gap: 0.5em">

Buttons a keyboard can reach

Enter on a row moves focus to the first gridlist.itemtrigger in it. Inside the row, Left and Right move between that row's triggers. Other keys belong to the focused button.

<gridlist.itemcontent>
	<gridlist.itemlabel>moodboard.png</gridlist.itemlabel>
	<gridlist.itemtrigger>Rename</gridlist.itemtrigger>
</gridlist.itemcontent>

Keyboard

The walk skips disabled rows.

Key What it does
Down or Up arrow Focus the row below or above this one on screen.
Left or Right arrow Focus the row to the left or right. Inside a row, move between its triggers.
Home or End Focus the first or the last row.
Enter or F2 Move focus to the first trigger in this row.
Escape Inside a row, move focus back to the row. On a row, let go of every picked row.
Space Pick the focused row, or let it go.
Shift and an arrow Pick every row from the starting row to the new one. Needs multiple.
Ctrl or Cmd and A Pick every row. Needs multiple. Without it, the page gets the keys.
A letter Focus the next row whose label starts with that letter. Type more letters to narrow it.

The letter search reads gridlist.itemlabel when a row has one, and the row's whole text when it does not.

Styling

The family ships one CSS rule in the markless layer. A selectable list gets user-select: none, so a Shift click does not also select the page's text.

Attribute On When
ui-selected item, itemindicator This row is picked.
ui-disabled root, item The list or this row is disabled.
ui-value item Always. It holds the row's value.
ui-selectable root Rows can be picked.
ui-multiple root multiple is set.
ui-inside root Focus is on a trigger inside a row.

gridlist.itemindicator is your "picked" mark. It stays in the page, so show it with [ui-selected].

API

Every prop is optional unless its row says it is needed.

gridlist.root

Prop Type What it does
value readonly string[] The picked rows, by value. The default is an empty list.
selectable boolean Rows can be picked, one at a time. A second click lets a row go.
multiple boolean Several rows can be picked at once. It also turns on selectable.
disabled boolean No row can be reached or picked, and the list leaves the Tab order.
wrap boolean A walk off the last row comes back to the first.
onChange (value: readonly string[]) => void Called with the picked rows when they change.

The root renders a <div role="grid"> named by gridlist.label. With multiple, it also has aria-multiselectable="true". Every other prop goes on that <div>.

gridlist.label

A <span>. The grid's aria-labelledby points at it.

gridlist.item

Prop Type What it does
value string Needed. The row's name in the picked list. No two rows can share one.
disabled boolean The walk skips this row, and nobody can pick it.

A <div role="row">. When rows can be picked, it has aria-selected set to true or false.

gridlist.itemcontent

A <div role="gridcell">. Each row holds exactly one, and everything in the row goes inside it.

gridlist.itemlabel

A <span>. The letter search reads it.

gridlist.itemtrigger

A <button type="button" tabindex="-1">. Tab skips it, and Enter on its row moves focus to it. It is disabled while its row or the list is disabled.

gridlist.itemindicator

A <span aria-hidden="true">. It gets ui-selected while its row is picked. Screen readers skip it, because the row already reports aria-selected.