Repository navigation
Description
Problem
The DataTable MVP (#161) renders a fixed set of rows passed in via rows prop. There's no built-in affordance for the consumer to add or remove rows — they have to wire their own button/control outside the table.
For row-per-record editors (shortcuts editors, lookup tables, settings tables), add/remove is a core interaction. Without it baked in, every consumer wires the same UX themselves and gets the focus management wrong (where does focus go after add? after remove?).
Impact
- Consumers reimplement add/remove plumbing per use case.
- Keyboard accessibility on add/remove is non-trivial — focus must land on the new row's first editable cell (add) or on a sensible neighbor (remove). Most consumers won't get this right.
- Screen reader announcements ("row added", "row removed") need wiring; without a built-in pattern, consumers won't add them.
Suggested Approach
Add two opt-in affordances to DataTable:
interface IDataTableProps<T> {
// ...existing
onAdd?: () => T; // returns the new row to append; absence hides Add button
onRemove?: (row: T, index: number) => void; // absence hides Remove control per row
}- Add button — rendered in the toolbar next to Save/Discard. Calls
onAdd, appends the returned row, focuses the first editable cell of the new row, announces "Row added" via live region. - Remove per-row — small icon button at the row's start or end (configurable). Calls
onRemove, focuses the previous row's first editable cell (or next row if removing the first row), announces "Row removed". - Keyboard shortcuts (optional in v1, follow-up if not):
- Enter on the last row's last cell while in edit mode: commit + add new row + focus first cell
- Backspace on an empty row's first cell: remove row + focus previous row
The keyboard shortcuts mimic spreadsheet UX. The buttons cover discoverability for users who don't know the shortcuts.
Context
Layered on top of #161 (DataTable MVP). The MVP works without this; this issue adds the affordances when consumers want them.
Activity
[-]DataTable: row add/remove with keyboard affordances[/-][+]Table: row add/remove with keyboard affordances[/+]