Editable Table
HkEditableTable is the inline-editing shell composed on HkTable: the grid, the header rhythm, row hover, section bands, the scroll registration and every structural / accessibility decision stay in that one component, and this shell adds the editable layer on top — which slot renders a cell, where the remove affordance goes, one validation line per invalid row, and the add-row band under the grid. A change to HkTable's internals therefore reaches editable grids for free instead of forking them.
It is Vue only — there is no Rust twin, so this page has no hikari rust fences; the mirror family does not carry a second implementation of the grid, and an editable Rust host composes editors into its own cells or uses Table read-only.
It is fully controlled: the shell never mutates rows and never mutates a row object. It emits intent (add, remove(row, index)) and the host applies it to its own reactive array; validation is a pure function the shell calls on every render. That is what keeps undo stacks, server drafts and unsaved-changes guards possible — and it is why editing a cell is your editor emitting to your data, with the shell supplying only the place and the accessibility wiring.
- When the rows are read-only and the job is browsing or bulk selection, use HkTable directly — it also carries the features this shell deliberately does not re-expose (sorting, dragging, selection).
- When each record is better read as a row of title / subtitle / trailing controls than as a grid of columns, use HkCardList.
- The add / remove affordances here are bare icon buttons; a page-level "create" action belongs in a HkButton in the page chrome.
Import
;
Columns, rows and the slot contract
The column shape is a trimmed copy of HkTable's: key, title, and optionally width, align and headerLabel (the screen-reader-only name for a glyph column). Sorting, dragging and selection flags are not re-exposed — the shell does not forward them.
The grid's cells come from slot pairs, one pair per column key:
- cell-<key> — the display of that column. Omitted, the shell lets HkTable render row[key] as text.
- edit-<key> — the editor: any element the host owns (its own input, its own select, a plain contenteditable). An editor wins over the display slot while the table is enabled; with disabled set the shell falls back to the display slot, so one disabled flag turns the whole grid into a readable read-only grid without the host re-slotting anything.
- row-error — one message line for an invalid row.
Both cell slots receive the same payload, { row, value, index, error, errorId, disabled }. index is the 0-based display position (the same index the shell uses for its own row lookup), error is that row's message or null, and errorId is the id of the rendered error line — null when the row is clean, so an editor binds it to aria-describedby only when there is something to read.
rowKey is required: it is the row identity for the grid's keys and for the error lines. A row whose rowKey field is missing falls back to its display index, exactly like HkTable.
The cells are given as slots, and a slot function receives the column as its object key, so the name is written as a quoted key: v-slots={{ "edit-name": … }}. Without any cell-<key> or edit-<key> for a column, that column stays HkTable's own text cell.
| Plan | Unit price | |
|---|---|---|
- Row 2: A plan needs a name.
Two details worth reading off that card: the second row starts with an empty name, so its message line is under the grid before anybody touches it — a required field on a pre-existing row is invalid from the first paint, which is why the default line names the row ("Row 2: …"). And canRemove returns false once one row is left, so the last row's trash button renders disabled rather than disappearing.
Validation lines and the read-only switch
validate(row, rows) is called per row on every render, never cached across changes: a host that mutates a nested field in place (a v-model on row.email) still gets fresh messages, because the array identity is the truth. A null, an empty string or a non-string return counts as clean; anything else is invalid.
The shell owns where the messages go and what ids they carry, not their wording. Every invalid row gets one <li> in a polite live region under the grid, keyed by the row identity and tagged with the id handed to the cells as errorId; the default text is the localized "Row N: message" (one-based, so the first row is “Row 1”), and the row-error slot replaces it with the host's own copy. The remove button's wrapper also carries data-row-invalid for that row, so a stylesheet can tint the trailing cell — the grid itself has no invalid-row paint.
disabled is one switch for the whole grid: every editor slot falls back to its display slot, the remove buttons and the add band are inert, and the root carries data-disabled. Nothing needs to be re-slotted.
| Environment variable | Value | |
|---|---|---|
| DATABASE_URL | ||
| LOG_LEVEL | debug |
- Line 1: DATABASE_URL has no value.
That grid is disabled end to end, and it still shows everything a reader needs: the editors render in their disabled state, DATABASE_URL announces its own validation line (rewritten by the row-error slot), and the add band and the remove buttons are present but inert. Note the shape of the rows here — value is the cell a host would normally edit, so keep a display slot beside the editor: a grid without cell-value falls back to row[key] as plain HkTable text at any time, and that fallback drops whatever formatting the display slot added.
Add, remove and the trailing column
canAdd renders the add band under the grid; a press emits add with no payload and the host appends its own draft row. canRemove is a per-row gate: providing it at all renders a synthetic trailing column (width 48px, right-aligned, headed by a screen-reader-only "Row actions" label), and each row gets a ghost trash button unless the gate returns false for it. The remove button is disabled while the whole table is disabled, stops propagation so HkTable's copy layer and row handlers never see the press, and emits remove(row, index) with the row it was rendered for — a host can filter by identity rather than trusting the index.
addLabel, emptyText, caption and the default strings are localized through the library's i18n table (hikari::editableTable.*); passing emptyText is how a grid says something more specific than "No rows yet".
The third sample also shows the shell's own lifecycle: an empty grid keeps its header, so the empty state is a cell rather than a blank surface.
| Field | Hint |
|---|---|
| No custom field yet | |
The empty card still has its header and its caption; pressing the add band lands a draft row whose empty label immediately raises the validation line, and with no canRemove gate the grid has no trailing column at all — the remove affordance is opt-in, not a default.
API
Vue
Props
| Name | Type | Default | Required |
|---|---|---|---|
| columns | Array as PropType<HkEditableColumn[]> | — | ✓ |
| rows | Array as PropType<Record<string, unknown>[]> | () => [] as Record<string, unknown>[] | — |
| rowKey | String | — | ✓ |
| validate | <code>Function as PropType< (row: Record<string, unknown>, rows: Record<string, unknown>[]) => string | null ></code> | undefined | — |
| canAdd | Boolean | false | — |
| canRemove | Function as PropType<(row: Record<string, unknown>) => boolean> | undefined | — |
| addLabel | String | undefined | — |
| emptyText | String | undefined | — |
| caption | String | undefined | — |
| disabled | Boolean | false | — |
Emits
| Event | Payload |
|---|---|
| add | — |
| remove | Record<string, unknown>, number |
Accessibility
- The grid is HkTable, so its semantics are the table's: a real <table> with one <thead>, column headers per column, and the screen-reader-only caption as the table's name. An empty grid still renders its header row plus the "no rows" cell, which the shell fills with emptyText rather than HkTable's own default.
- Every invalid row's message is an <li> inside a aria-live="polite" region under the grid, and each carries the generated id handed to the cell slots as errorId. Bind that id to the editor's aria-describedby and a screen-reader user hears the message with the field rather than only after leaving a field. The id is null for a clean row, so bind it conditionally.
- The trailing remove button has the accessible name "Remove row + 1-based row number", and the trailing column's header cell carries "Row actions" as its aria-label (with no visible text) — the remove affordance is named in both directions.
- The add band is a real <button type="button"> labelled by addLabel (localized "Add row" by default), so it is reachable in the natural Tab order after the grid.
- disabled is not a visual-only state: the editors are gone (display slots take over), the remove buttons carry the native disabled attribute and drop out of the Tab order, and the add button does too. Do not disable a grid to express "not editable yet" for one row — use the row's own editor state instead.
Related components
- HkTable — the grid this shell composes; sorting, dragging, selection and row actions live there.
- HkInput — the editor most cells use, with its own label / hint / error wiring.
- HkButton — the page-level create action the add band is not.
- HkCardList — the row-shaped alternative for records that read better as lines than as columns.