SheetEditor
A spreadsheet editor: a cell grid with formulas, a formula bar, formatting, selection stats, and CSV export. You own the sheet and its undo history.
Installation
npx dafink-ui add sheet-editorAlso installs: Menu, Models, Popover, Select, Charts, Modal, Button, Input, Color-picker
Demo
Props
| Name | Type | Default | Description |
|---|---|---|---|
| sheet | Sheet | — | The sheet being edited (controlled): a title, row and column counts, a cells map keyed by A1 address, and column widths. A cell's value is what was typed, so formulas are stored as "=SUM(A1:A5)". |
| onChange | (next: Sheet, coalesceKey?: string) => void | — | Every edit, as the whole next sheet. Consecutive changes sharing a coalesceKey (typing in one cell, dragging a column edge) belong in one undo step. |
| history | EditHistory | — | { undo, redo, canUndo, canRedo }: undo and redo from the toolbar and ⌘Z / ⇧⌘Z. Omit to hide the undo controls. |
| toolbarEnd | ReactNode | — | Host actions in the top-right cluster, before Download (e.g. a save status). Style buttons with the exported SHEET_TOOLBAR_BUTTON class to match. |
| status | string | — | A host message for the polite status line. Shown instead of the editor's own messages while set. |
| highlight | string | — | Cells someone else (like an AI) is editing right now, in A1 notation ("B2:C5"): outlined, pulsing, and scrolled into view. |
| highlightLabel | string | 'AI' | Text on the tag over the highlighted range. |
| onAsk | (context: SheetAskContext) => void | — | Adds an "Ask AI" button to the toolbar. Called with the selected range, the active cell, and the typed values in the selection. |
| className | string | '' | Extra classes on the root. It fills its container, so give the container (or this) a height. |
Accessibility
The editor is a named role="region" with three tab stops: the formula bar input, the grid, and the floating formatting toolbar at the bottom (a role="toolbar" where the arrow keys move between buttons). The grid is a single tab stop using aria-activedescendant: focus stays on the grid while the active cell is announced, and every cell is a gridcell with its row and column index and aria-selected when it is in the selection. Only the visible rows are rendered, so aria-rowcount reports the real size. Editing opens a text input in the cell (or in the formula bar); committing or cancelling returns focus to the grid. Errors are always shown as their code (#DIV/0!, #REF!) and not just in red. Copy, cut, and paste use the system clipboard as tab-separated text, so they work with other spreadsheets. Tab leaves the grid from the last column rather than trapping focus.
| Key | Function |
|---|---|
| arrow keys | Move the active cell; with Shift, extend the selection. |
| cmd+arrow keys | Jump to the edge of the sheet. |
| tab | Move right (Shift+Tab: left). At the edge, focus moves on to the next control. |
| enter | Start editing the active cell. While editing, commit and move down (Shift+Enter: up). |
| f2 | Start editing the active cell. |
| escape | Cancel an edit, or collapse the selection to the active cell. |
| delete | Clear the selected cells’ contents (formatting stays). |
| cmd+a | Select every cell. |
| cmd+b | Bold the selection (⌘I for italic). |
| cmd+c | Copy the selection (⌘X cuts, ⌘V pastes at its top-left cell). |
| cmd+z | Undo (when the host passes history). ⇧⌘Z redoes. |
| home | Jump to the first column of the row; End jumps to the last. |
| page down | Move ten rows down (Page Up: up). |