Editable Table
Edit cells in place like a spreadsheet, with validation, undo and one Save.
PROGet Editable Table and 168 other Pro components with pro lifetime — Get Pro
- Category
- Data Tables
- Access
- ProPro · unlocked
- Source
- 866 lines · one file
- States
- 6 drawn
The decision inside it
It never edits your rows
The table keeps a working copy beside your data, and pending is simply the difference between the two. The corner marks, the count in the bar, Discard and the list handed to onSave are all that one diff, so they can never disagree.
When to use it
Use Editable Table when people edit records in place like a spreadsheet: arrows, Enter and Tab, typed columns, validation per cell, undo and redo, and a pending bar with Save. onSave gets only the changes. For read-only tables, use Data Table.
Installation
How you get it
Paste this into Claude Code, Cursor, Codex or any coding agent. It installs the file and uses it as it is, instead of writing a new one.
Use Liro's Editable Table for this.
Install it: npx shadcn@latest add @liro/editable-table
(the @liro registry is set up in components.json, with LIRO_KEY in .env.local)
Import it from @/components/ui/editable-table.
Do not rewrite or restyle it. Pass my data through its props
and keep its built-in states.For the full brief with every prop and the mistakes assistants usually make, use Copy prompt above. Pro components install through the @liro registry with your CLI token: see the Namespaced tab.
Usage
import { EditableTable, type EditableColumn, type CellChange } from "@/components/ui/editable-table";
type Product = { id: string; name: string; price: number; status: string };
const columns: EditableColumn<Product>[] = [
{ key: "name", header: "Product", validate: (v) => (String(v).trim() ? undefined : "Name is required") },
{ key: "price", header: "Price", type: "currency" },
{ key: "status", header: "Status", type: "select", options: ["Active", "Archived"] },
];
export function PriceList({ products, save }: { products: Product[]; save: (changes: CellChange<Product>[]) => Promise<void> }) {
return <EditableTable label="Products" rows={products} columns={columns} getRowId={(p) => p.id} onSave={save} />;
}API reference
“Copy prompt” above puts a full brief on your clipboard, install command, dependencies, props, and the mistakes an assistant usually makes with this component.
Props
Read from the component’s own TypeScript interface when the site is built, so this table cannot drift from the file you install.
| Type | Notes | ||
|---|---|---|---|
label | string | Yes | What the rows are, for the grid's accessible name: "Customers". |
rows | T[] | Yes | The saved rows. The table keeps its own working copy on top of them and never changes these. |
columns | EditableColumn<T>[] | Yes | – |
getRowId | (row: T) => string | Yes | A stable id for a row. |
onSave | (changes: CellChange<T>[]) => Promise<void | Record<string, string>> | Yes | Called by Save with everything pending. Resolve with `{ [rowId]: message }` to reject rows: they stay pending and show the message. |
onChange | (changes: CellChange<T>[], rows: T[]) => void | No | Called after every step (an edit, a paste, a row added or deleted, undo, redo) with what it changed and the working rows. |
defaultDraft | T[] | No | Unsaved work to start from, such as a draft you kept in storage. What differs from `rows` is pending. |
readOnly | boolean | No | Turns editing off: no editors, no row actions. |
newRow | () => T | No | Makes a blank row with a fresh id. Adds the "Add row" button. |
selectable | boolean | No | Adds the checkbox column and "Delete N rows". Default true. |
toolbar | React.ReactNode | No | The left side of the toolbar: a title, a filter. |
currency | string | No | ISO 4217 code for `currency` columns. Default "USD". |
Dependencies
npm packages
clsxdate-fnsframer-motionlucide-reacttailwind-mergeLiro foundations, installed alongside it
liro-themebuttoncalendarcheckboxinputpopoverselectstatetooltipStates
All of them are drawn by the component. None is left for you to design.
- At rest
- Editing a cell
- Invalid cell
- Pending changes
- Saving
- One row rejected
Accessibility
- Keyboard reachable throughout, in visual order
- Focus trapped in overlays, Escape closes them
- Focus returns to whatever opened it
- Live regions announce what changed, not that something did
- Honours prefers-reduced-motion
Responsive behavior
- Sizes to its container, not the viewport
- Usable from 320px up
- Pointer-based interaction, so trackpad and touch both work
- No hover-only affordances