GhostDataGrid
GhostDataGrid is an editable data grid that follows the APG data grid pattern. It renders a native table with grid semantics, a single tab stop, arrow-key movement between cells, and a labeled single-line text editor on the cells you mark editable. You own the rows: the grid never sorts, clones, or writes them. It proposes a changed value through editRequest, and your app accepts it by updating data or rejects it through cellErrors.
Import it from @ghostvue/vue. It is headless: style it through the styling hooks. The full contract is the GhostDataGrid specification.
Change Build's estimate from 3 to 8: Enter proposes once, the application saves through a per-cell queue and re-sorts the rows, and focus follows Build's Estimate cell to its new row. Estimates over 20 days are rejected with a visible, announced message.
Tab into the grid, move to Build's Estimate, and press Enter. Type 8 and press Enter again. The app saves the value and re-sorts the rows, and focus follows Build's Estimate to its new row. Try 30 to see a rejection: the cell keeps its value and shows, describes, and announces the reason.
DataGrid or DataTable
Use GhostDataTable for reading and acting on records: sorting, filtering, pagination, selection, and detail rows. It keeps native table semantics, and Tab moves through the controls you render.
Use GhostDataGrid when people edit values in place and move between cells like a spreadsheet. A grid is one composite widget: Tab enters and leaves it, and the arrow keys move inside it. Do not wrap a read-only list in a grid to get arrow keys; screen reader users then lose the table reading commands they expect from a plain table.
Define rows and columns
A named grid with one Tab stop and arrow-key, Home/End, and Ctrl+Home/End navigation over read-only cells, with a row header column.
Every grid needs rows, columns, a row ID function, and an accessible name from aria-label or aria-labelledby. The row ID must stay the same across saves and reorders, because focus and open drafts follow it. Column IDs must be unique too.
Mark one column as the row header so each row starts with a row header cell. Editors are named from it ("Estimate, Build"), and screen readers announce it when moving down a column. The column options table lists how a column reads, renders, and edits its value.
Provide the empty slot. When there are no rows or columns, the grid itself becomes the named Tab stop and describes itself with that content.
Edit a cell
Set editable: true, or a function of the row, on a column. On an editable cell, Enter, F2, or a second press on the already active cell opens the editor with the whole value selected.
Entercloses the editor, returns focus to the cell, and then emitseditRequestonce, but only when the text changed.Escapediscards the draft and returns focus to the cell. It is default-prevented, so an enclosing dialog stays open; a secondEscapein navigation reaches the dialog.TabandShift+Tabemit a changed draft once and move focus out of the grid, as in a form. The edited cell becomes the re-entry target.- Clicking or tapping anywhere else discards the draft and leaves focus where the press put it.
The edit request names the cell and carries the previous value and the draft text, which your app parses. The editor starts from the column's toDraftText result, the value as a string by default, and "changed" means the text differs from that starting text.
Accept or reject an edit
The application leaves data unchanged and sets a cellErrors entry: the cell keeps its value, shows and announces the message, and reopens from the current value with aria-invalid.
To accept, replace data with a new array that holds the new value. You may reorder it; the grid follows the edited cell by its row and column IDs.
To reject, leave data alone and add a cellErrors entry with the row ID, column ID, and a message. Write the message as a full sentence that names the row, such as "Test estimate not saved: a task can take at most 20 days." The grid shows it in the cell, references it from the cell's description, marks the cell data-invalid="true", and announces each new entry once through its polite status element. Remove the entry on the next proposal for that cell. Reopening the editor starts from the current value and marks the editor invalid.
Saves can finish out of order. The estimate example above queues saves per cell, so the cell always ends with what the server accepted last and a newer proposal's error is never overwritten by an older save.
Lock rows and format values
editable as a per-row callback keeps done tasks reachable but read-only, and a cell render hook shows "3 days" while toDraftText opens the editor with the raw number.
editable: (task) => !task.done keeps finished tasks read-only. Locked cells stay reachable with the arrow keys and expose aria-readonly="true"; Enter, F2, and a second press do nothing on them.
To show "3 days" but edit the raw number, render the display text with cell and keep toDraftText: (value) => String(value) for the editor. Set editorInputMode: 'numeric' for a number keypad on touch devices.
Right-to-left
A grid that inherits dir="rtl": ArrowLeft and ArrowRight follow the physical neighbor, Home and End follow reading order, and the editor owns caret movement.
The grid follows the page's direction. Left and right arrows move to the physical neighbor, so ArrowLeft moves forward in a right-to-left row. Home and End follow reading order, so Home reaches the rightmost cell. In the editor, arrow keys move the caret and never the active cell.
Keyboard
Navigation mode
| Key | Action |
|---|---|
Tab / Shift+Tab | Enter the grid on the remembered cell (first data cell on first entry, or the empty grid), or leave it. |
ArrowRight | Physical right-hand neighbor in the row. Stops at the edge. |
ArrowLeft | Physical left-hand neighbor in the row. Stops at the edge. |
ArrowDown | Same column, next row. Stops on the last row. |
ArrowUp | Same column, previous row. Stops on the first row. |
Home / End | First or last cell of the row in reading order. |
Ctrl+Home | First cell of the grid. Ctrl on every platform, including macOS. |
Ctrl+End | Last cell of the grid. |
Page Down | Same column, forward by one fewer than the number of fully visible rows (at least one). Clamped to the last row. |
Page Up | Same column, back by the same step. Clamped to the first row. |
Enter / F2 | Open the editor on an editable cell. Nothing on a read-only cell. |
Every movement scrolls its target into view. Other keys are left to the browser and never move the active cell or open an editor: Space, letters, delete keys, Escape, Shift with an arrow, and Cmd chords.
Edit mode
| Key | Action |
|---|---|
Arrows, Home, End | Move the caret and select text. The grid does not move between cells. |
Enter | Close the editor, return focus to the cell, then propose a changed draft once. |
Escape | Discard the draft and return focus to the cell. |
Tab / Shift+Tab | Propose a changed draft once and leave the grid in that direction. |
While an IME composition is active, Enter and Escape belong to the IME: confirming a composition never submits, and cancelling one never discards the draft.
Pointer and touch
A completed click or tap on any body cell makes it the active cell and focuses it, including read-only cells. A press that turns into a scroll, or is released outside the cell, changes nothing. A second press on the active editable cell opens the editor, so a double-click opens it but a single tap never raises the on-screen keyboard by surprise.
Jump to a cell
Call focusCell on the template ref from a control such as a "Go to first overrun" button. It moves focus to that cell in navigation mode, discards an open draft without emitting, and never opens the editor. See the template ref table.
Behavior when data changes
- Inserting or reordering rows keeps focus, and an open editor keeps its draft and selection.
- Removing the focused row or column moves focus to the next surviving one, then the previous one. When every ID is replaced, focus moves to the first new row or column. Emptying the grid focuses the named empty grid, and the first rows you add move focus to the first cell.
- An open draft is discarded, without emitting, when its row or column is removed, the cell becomes read-only, or
toDraftTextfor the cell now returns different text. A new row object with the same value keeps the draft. - Updates while focus is outside the grid never move focus; they only change where
Tabre-enters.
Accessibility
- Name every grid with
aria-labeloraria-labelledby. Development builds warn (GHOST020) when neither is present. - Give each row a row header, or set
editorLabelon editable columns, so every editor has a distinct name. UseeditorLabelto rename or localize it, for example "Estimate for Build". - Write cell errors as complete sentences that make sense when read alone.
- If you place the grid in a scroll container, give that wrapper
role="region", an accessible name, andtabindex="0".Page UpandPage Downmeasure the visible rows through it. - Header cells hold text only; the grid has no sort buttons or other controls in its header in this release.
- Automated keyboard and axe checks are not a screen reader review. NVDA with Firefox and VoiceOver with Safari reviews are required before the grid is promoted from
experimental.
Styling hooks
| Hook | Element |
|---|---|
data-part="grid" | The <table role="grid">. class, style, and attributes go here. |
data-part="row" | Header and body rows. |
data-part="columnheader" | Column headers. |
data-part="cell" | Body cells, including row headers. |
data-part="editor" | The text input while a cell is edited. |
data-part="cell-error" | The visible error message inside a cell. |
data-part="empty" | The cell holding the empty slot. |
data-part="status" | The visually hidden status element after the grid. |
data-active="true" | The remembered active cell. |
data-editing="true" | The cell whose editor is open. |
data-readonly="true" | Read-only cells. |
data-invalid="true" | Cells with a cellErrors entry. |
Give cells a visible focus style, for example [data-part='cell']:focus-visible { outline: 2px solid currentColor; }. The grid renders the table and its status element side by side, so in a <style scoped> block reach its parts through a wrapper with :deep(), as the estimate example does.
Custom markup
useGhostDataGrid is the escape hatch for apps that must render their own grid markup. Spread each attribute bag in the table below on its element, render every row and column in the returned order, mount one editor input only for the editing cell, and render the status message in a polite status element outside the grid. GhostDataGrid is the supported path; custom markup that drops a bag or reorders cells is unsupported.
| Member | Use |
|---|---|
rows, columns | Rows and columns to render, in order. |
activeCell, editingCell | The remembered active cell, and the cell whose editor is open. |
isEditable(cell) | Whether a cell is editable now. |
statusMessage | Text for the polite status element. |
getGridProps() | Attributes for the grid element. |
getRowProps(rowId) | Attributes for each body row. |
getCellProps(cell) | Attributes and handlers for each body cell. |
getEditorProps() | Attributes and handlers for the editor input. |
focusCell(cell) | Same as the component's exposed method. |
API
| Prop | Type | Default | Description |
|---|---|---|---|
cellErrors | readonly DataGridCellError[] | "[]" | App-controlled messages shown on cells; the grid never adds or clears entries. |
columns | readonly DataGridColumnDef<TData>[] | Required | Column definitions in reading order. Column IDs must be unique. |
data | readonly TData[] | Required | Consumer-owned rows in display order. Never sorted, cloned, or mutated. |
getRowId | DataTableGetRowId<TData> | Required | Stable row ID, as in DataTable. Focus and open drafts follow it across reorders. Row IDs must be unique. |
| Event | Payload | Description |
|---|---|---|
editRequest | DataGridEditRequest | Proposes a changed draft once, after Enter (the editor has closed and focus is back on the cell) or during Tab/Shift+Tab. Not emitted for unchanged drafts, Escape, focus loss, removal, or invalidation. |
| Slot | Slot props | Description |
|---|---|---|
empty | — | Accessible empty-state content shown inside the empty grid. |
Column options
| Option | Description |
|---|---|
id | Unique column ID, used in edit requests, errors, and focusCell. |
header | Column header text. |
accessorKey / accessorFn | Reads the cell value from the row. |
cell | Renders display content. Receives the value, row, editable, and error. |
rowHeader | Renders this column's cells as row headers. One column at most. |
editable | true, or a function of the row. Defaults to read-only. |
toDraftText | Text the editor starts from, and the baseline for "changed". Defaults to the value as text. |
editorLabel | Function returning the editor name. Defaults to the header and row header, such as "Estimate, Build". |
editorInputMode | inputmode for the editor, such as numeric. |
meta | Your own data, passed through untouched. |
Edit request
| Field | Description |
|---|---|
rowId | ID of the edited row. |
columnId | ID of the edited column. |
previousValue | The cell value when the editor opened. |
draftText | The editor's text. Parse and validate it in your app. |
Template ref
| Member | Description |
|---|---|
focusCell(cell) | Focuses the cell with { rowId, columnId } in navigation mode. Returns false if it is missing. |
Not in this release
Custom cell editors, in-cell buttons, header controls, type-to-edit, clear-on-Delete, selection, treegrid rows, and virtualization are out of scope for 0.3.0. See the specification for what is planned to be additive.