gridlist
onChange called 0 time(s)
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>;}
.desk { display: grid; gap: 0.5em; width: min(31rem, 100%); font-family: 'Shantell Sans', system-ui, sans-serif; font-size: var(--step--1); line-height: 1.5; color: var(--ink);}.list { display: grid; gap: 0.5em; margin-block-end: 0.4em;}.list:focus-visible { outline: 2px solid var(--ink); outline-offset: 4px;}.caption { font-family: 'Joy Elia', system-ui, sans-serif; font-size: var(--step-0);}.row { border: 1px solid var(--ink); border-radius: 6px; outline: none; cursor: pointer; transition: background 140ms ease;}.row:hover { background: color-mix(in srgb, var(--purple) 16%, var(--cream)); html.dark & { --ink: var(--on-accent); color: var(--on-accent); }}.row[ui-selected] { background: color-mix(in srgb, var(--purple) 26%, var(--cream)); html.dark & { --ink: var(--on-accent); color: var(--on-accent); }}.row:focus-visible { outline: 2px solid var(--ink); outline-offset: 3px;}.row[ui-disabled] { opacity: 0.55; cursor: not-allowed;}.cell { display: flex; gap: 0.7em; align-items: center; padding: 0.55em 0.8em;}.tick { display: grid; place-items: center; box-sizing: border-box; width: 1.3em; height: 1.3em; flex: none; border: 1px solid var(--ink); border-radius: 4px; background: var(--paper);}.tick-icon { width: 0.95em; height: 0.95em; visibility: hidden;}.tick[ui-selected] .tick-icon { visibility: visible;}.name { flex: 1; min-width: 0; overflow-wrap: anywhere;}.size { white-space: nowrap;}.action { padding: 0.2em 0.6em; border: 1px solid var(--ink); border-radius: 6px; background: transparent; color: var(--ink); font: inherit; font-family: 'Shantell Sans', system-ui, sans-serif; cursor: pointer; transition: background 140ms ease;}.action:hover { background: color-mix(in srgb, var(--purple) 16%, var(--cream)); html.dark & { --ink: var(--on-accent); color: var(--on-accent); }}.action:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px;}.action:disabled { cursor: not-allowed;}.readout { margin: 0;}.readout-value { color: var(--ink); font-family: var(--font-mono);}@media (max-width: 30rem) { .size { display: none; }}@media (prefers-reduced-motion: reduce) { .row, .action { transition: none; }}
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
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.
A gallery that wraps
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.