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-editor

Also installs: Menu, Models, Popover, Select, Charts, Modal, Button, Input, Color-picker

Demo

Props

NameTypeDefaultDescription
sheetSheet—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.
historyEditHistory—{ undo, redo, canUndo, canRedo }: undo and redo from the toolbar and ⌘Z / ⇧⌘Z. Omit to hide the undo controls.
toolbarEndReactNode—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.
statusstring—A host message for the polite status line. Shown instead of the editor's own messages while set.
highlightstring—Cells someone else (like an AI) is editing right now, in A1 notation ("B2:C5"): outlined, pulsing, and scrolled into view.
highlightLabelstring'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.
classNamestring''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.

KeyFunction
arrow keysMove the active cell; with Shift, extend the selection.
cmd+arrow keysJump to the edge of the sheet.
tabMove right (Shift+Tab: left). At the edge, focus moves on to the next control.
enterStart editing the active cell. While editing, commit and move down (Shift+Enter: up).
f2Start editing the active cell.
escapeCancel an edit, or collapse the selection to the active cell.
deleteClear the selected cells’ contents (formatting stays).
cmd+aSelect every cell.
cmd+bBold the selection (⌘I for italic).
cmd+cCopy the selection (⌘X cuts, ⌘V pastes at its top-left cell).
cmd+zUndo (when the host passes history). ⇧⌘Z redoes.
homeJump to the first column of the row; End jumps to the last.
page downMove ten rows down (Page Up: up).