shadcn.io is not affiliated with official shadcn/ui
Keyboard Navigable Data Grid Block for React
A spreadsheet-like sprint tracker in a fixed window, a grid with one tab stop that moves with arrows, Home, End and Page keys, edits with Enter and cancels with Escape.
Installation
Overview
Give a table the full keyboard model of a spreadsheet, with this keyboard navigable data grid for React with Base UI. Ten tasks of a sprint sit in a native table with role="grid" in a window of fixed height. Exactly one cell is in the Tab order and it follows focus and clicks. The arrow keys move one cell, Home and End the ends of the row, Ctrl with Home or End the first and last cell, and Page Up and Page Down five rows, and in a right-to-left page the arrows mirror. Space checks a row, Enter edits the cell (Title, Owner and Points; ID and Status say they are read-only), Enter saves and Escape puts the old text back. A strip under the grid reads out the active row and holds the reason a value is refused, and an Edit cell button does for a mouse or a tap what Enter does. It's hand-built from a native table, Input, Badge and Kbd, so it is identical on every library. For trackers, backlogs and any dense table power users live in.
FAQ
Which keys does the grid answer to?
Arrow keys move one cell. Home and End go to the first and last cell of the row, Ctrl with Home or End to the first and last cell of the grid, and Page Up and Page Down jump five rows. Space toggles the row's check. Enter opens the cell for editing, saves what you typed, and Escape cancels. Tab leaves the grid: there is a single tab stop, not one per cell.
What changes in a right-to-left page?
The columns run from the right and Arrow Left and Arrow Right swap so the arrow that points toward a neighbour still moves to it; Home and End still mean the start and the end of the row. The IDs and numbers keep their left-to-right text.
How is the grid exposed to assistive technology?
It is a table with role grid, aria-rowcount and aria-colcount, aria-rowindex and aria-colindex on rows and cells, aria-multiselectable, aria-selected on checked rows and aria-readonly on the cells that cannot be edited. The focused cell is announced by the browser, and the status line at the foot only speaks actions, such as a row checked or a cell saved.
What happens when a value is not valid?
Enter keeps the cell open, marks the field invalid and writes the reason in the strip under the grid, in a line that is always reserved. Escape or leaving the field puts the old value back. A title must be 1 to 40 characters, an owner cannot be empty and Points is a whole number from 0 to 99.
What about phones and tablets?
The key legend is hidden below the medium breakpoint (its text stays available to screen readers), the grid scrolls sideways inside the window, a tap selects a cell, tapping the box checks a row and the Edit cell button edits the active cell. The window never changes height.
What stays local, and how do I wire it for real?
The tasks are typed in the file and edits and checks are this page's state; a reload brings the sample back. For real data, keep the grid and the key handlers, load your rows in place of the sample and send each saved cell from the commit step to your API.
Related
- Pro
Editable Cells Grid Table
Edit in placeA sales forecast grid where every number is a field, with live row and column totals, a dot on each changed cell, arrow keys and Enter between regions, Undo and Reset.
- Pro
Inline Cell Editing Table
Edit in placeA shop price list whose price and stock cells turn into a field in place, with Save, Cancel, Escape, a reserved line for the reason a value is refused and Undo.
- Pro
Row Selection Table
Select and actA stock list with a checkbox on every row, a head checkbox that shows a dash when only some are ticked, Shift-click range select and a live line that adds up the price of the ticked rows.
- Pro
File Explorer Table
Rows that openA file explorer window with a rail of places, a path bar with an Up button, and a table that lists one folder at a time, folders first, with sortable heads and a New folder button.
- Pro
Sortable Members Table
Sort and searchA members table whose column heads are buttons: press one to sort, again to reverse, a third time for the original order, with aria-sort on the active head, ties settled by name and a spoken line for each result.
- Pro
Quick Actions Table
Select and actA document table whose rows show Rename, Duplicate and Delete icon buttons on hover or focus, with tooltips that name the document and show the key, and a Delete that becomes a quiet row with Undo.