Shadcn Table with Draft Rows
Type several new rows straight into the table, see what needs fixing as you go, then save or discard them together. Built here as an expense report; the same works for order items or stock counts.
$ npx shadcn add https://www.shad-table.dev/r/draft-rows-table.jsonExpense report November 2026
4 saved · $726.90
| Date | Description | Category | Amount | Actions |
|---|---|---|---|---|
| Nov 3 | Train to Lyon | Travel | $86.40 | |
| Nov 3 | Hotel Bellecour, 2 nights | Lodging | $312.00 | |
| Nov 4 | Client dinner | Meals | $148.50 | |
| Nov 10 | Figma, annual seat | Software | $180.00 | |
Duplicate? | ||||
Enter in a description or amount moves down a row, and adds one at the end. | ||||
3 new rows$191.30· 1 needs fixing1 possible duplicate
How it works
1.Saved rows and drafts in one table
The table gets one list: saved expenses, then the drafts, each tagged with its kind. Every column renders plain text for a saved row and an input for a draft, so new rows sit right under the ones they join, with the same columns. Drafts keep the raw text from their inputs until the batch is saved.
export type Row =| { kind: 'saved'; id: string; expense: Expense }| { kind: 'draft'; id: string; draft: Draft; number: number }
2.Errors show when they are useful
Rows are validated on every keystroke, but a field only shows its error after you leave it, so a half-typed row is not covered in red. Pressing Save with mistakes shows every error and moves focus to the first one. Blank rows are skipped, so an empty row at the end never blocks saving.
const visible = (field) =>(attempted && !isBlank(draft)) || touched.has(`${id}:${field}`)
3.Typing several rows from the keyboard
The date is a shadcn date picker limited to the report period, and the category a shadcn Select; both count as touched when they close. In the description and amount, Enter moves to the same field one row down and adds a row at the end, starting on the date of the row above. Removing a row moves focus to its neighbour, so focus is never lost.
if (i === drafts.length - 1) addRow(field)else focusTarget.current = { id: drafts[i + 1].id, field }
4.Possible duplicates warn, but do not block
A draft with the same date, amount and description as a saved expense, or as another draft, gets a Duplicate? note. It is a warning rather than an error, because two identical taxi rides in a day can be real.
export function duplicates(drafts: Draft[], existing: Expense[]): Set<string>
5.One save for the batch
Save sends every filled row together and turns them into saved rows, which flash green for a moment. Discard asks once more before throwing away rows with something typed in.
const added = summary.filled.map((d) => toExpense(d, newId()))setSaved((s) => [...s, ...added].sort(byDate))setDrafts([])