Skip to content
SENVENLI UI

Grid list

A list to move through with arrow keys and select from: rows with a visual, a title and status (`layout="stack"`), or tiles in a responsive grid with actions and drag to reorder (`layout="grid"`).
Rows
import {
  GridList,
  GridListItem,
  GridListSection,
} from "@senvenli/react/collection";

Examples

Rows in sections

Rows from data, grouped under small headers.

Picking a set

A checkbox per row, for acting on several at once.

One open row

`replace` selection with no checkboxes, for a list beside the record it opens.

Tiles: product photos

`layout="grid"`: tiles people know by their picture, picked as a set.

Reordering

Drag a tile or use its handle from the keyboard; the tile's own buttons do the same on touch.

Tiles that open

An icon as the media, and a press or Enter that opens the tile.

Guidelines

When to use it

  • Records read as one line each, and tables on narrow screens (layout="stack").
  • Items people recognize by an image: photos, documents, cards (layout="grid").

Use something else when

  • People compare several fields across records. Table
  • A plain choice of options in a form, not records to open. List box

Accessibility

Keyboard

KeysWhat happens
Arrow keysMove between rows, or between tiles in two dimensions.
EnterOpens the focused row or tile.
SpaceSelects the focused item.

Built in

  • Sections are named for screen readers.
  • Tile actions are always visible, so they need no hover and work on touch.
  • A drag handle gives the keyboard a way to reorder tiles.

You provide

  • An aria-label.
  • A name for each tile action that names the tile.

API reference

GridList

aria-labelRequired
string

Names the list ("Today's deliveries").

children
React.ReactNode

GridListItem rows, or ListSections of them; or give items (or sections) and renderItem.

items
readonly T[]
sections
readonly GridListSectionData<T>[]

Grouped rows under small headers ("Today", "Tomorrow").

renderItem
(item: T) => GridListItemProps | (item: T) => GridTileContent

One row's content for items / sections.

selectionMode
"none" | "single" | "multiple"
selectionBehavior
"toggle" | "replace"

How a press selects. toggle (default): each row has a checkbox and a press adds or removes it, for picking a set to act on. replace: no checkboxes; a press selects that row in place of the last, and with single the arrow keys move the selection, for a list that shows one open record beside it (an inbox's conversation). The selected row keeps its marker either way. With onAction as well, a press runs the action and selection needs the keyboard (React Aria's replace rule), so a replace list usually leaves onAction out.

selectedKeys
"all" | Iterable<Key>
defaultSelectedKeys
"all" | Iterable<Key>
onSelectionChange
(keys: Selection) => void
onAction
(key: Key) => void

Opens the row's record.

emptyState
React.ReactNode

Shown when there are no rows: an EmptyState or a sentence.

layout
"stack" | "grid"
itemKey
(item: T) => Key

The item's stable id; item.id by default.

dragAndDrop
{ onReorder: (keys: Set<Key>, target: { key: Key; position: "before" | "after" }) => void }

Reordering (photos): drag a tile, or focus its handle and use the keyboard. onReorder gets the moved keys and the tile they go before or after.

ref
React.Ref<HTMLDivElement>

The grid element. Focusing it focuses the tile React Aria keeps as focused (the next one after a removed tile), so it is the returnFocusRef for a confirm whose action removes the tile it was opened from.

GridListItem

idRequired
Key
leading
React.ReactNode

A visual at the start: an Avatar, an icon or a thumbnail.

titleRequired
string

The one primary line ("Ada Lovelace"); also the row's text for typeahead.

description
React.ReactNode

The context the reader scans for: item, time, place ("Order 1042 · 10:00 · Berlin").

trailing
React.ReactNode

At the end: a Badge for status, then a subtle icon-button menu.

href
string

Makes the row a link to the record.

GridListSection

titleRequired
string
childrenRequired
React.ReactNode