Documentation

@kanunilabs/datagrid-react


@kanunilabs/datagrid-react / EditorRenderContext

Interface: EditorRenderContext<TRow>

What a custom editor is handed. commit/cancel are the SAME handles the built-in editor uses, so a replacement participates in Tab-walking, batch changes and undo rather than living beside them.

The custom editor contract (P-4) — what the grid does around a renderEditor:

  • The editor is drawn inside a box the grid owns, marked data-kanuni-editor (display: contents, so it does not change the layout). Keys whose target is inside it are the editor's: the grid does not navigate, open, or type-to-edit on them. Two exceptions, both only when the editor's own handler did not call event.preventDefault(): Escape cancels the editor (cancel()), and Tab / Shift+Tab walk the focusable elements INSIDE the box (text box → "…" button) and only past the last (first) one commit and move to the next (previous) cell — commit({ move: 'next' }). Enter commits like the built-in editor (moves down, or stays with editKeys.enter; Shift+Enter stays) — except in a <textarea> or an editable region, where it types a new line. An editor that uses Enter itself (picking from its own list) calls preventDefault() in its handler. The editor's own shortcuts (F4, Alt+ArrowDown for its "…" button) are never taken by the grid.
  • Events from OUTSIDE the grid's DOM — a dialog the editor opens in a portal (Radix Dialog, a <dialog> under <body>) — never reach the grid's handlers, although React routes them through the editor's component tree: Enter, arrows, PageUp/PageDown, Space, Escape, Tab, F2, Insert, Ctrl+Delete, Ctrl+Z, clicks and double-clicks in that dialog change nothing in the grid or the editor session — also when the dialog holds another KanuniLabs grid. Escape in the dialog closes the dialog (its own business); a second Escape, back in the editor, cancels the editor.
  • Blur: the grid does not commit a custom editor on blur by itself. Put onBlur={ctx.commitOnBlur} on the editor's root element to commit when focus leaves it the way the built-in editors do. While a dialog of the editor is open call suspendBlurCommit(true) (before it takes focus) and suspendBlurCommit(false) when it closes: in between, neither commitOnBlur nor commitOn: 'row''s "focus left the grid" send runs.
  • Focus: after commit() / cancel() focus goes to the grid's scroller (the keyboard keeps working); after suspendBlurCommit(false) focus that fell to <body> (the dialog's opener is gone) goes back to the editor, or to the scroller when the editor has closed.

Type Parameters

TRow

TRow = GridRowData

Properties

api

api: EditorRowApi

Writes to this row (setRowValues).


ariaLabel

ariaLabel: string

The column's header text — for the editor's aria-label.


cancel

cancel: () => void

Returns

void


columnId

columnId: string


commit

commit: (options?) => boolean

Commit the value. False when a rule refused it (the editor stays open). Without options it stays on the cell, as always.

Parameters

options?

EditorCommitOptions

Returns

boolean


commitOnBlur

commitOnBlur: (event) => void

A focusout handler for the editor's root element: commits (staying on the cell, focus left where the user put it) once focus has gone somewhere that is not part of the editor — not inside its box, not one of the grid's popups, not an element marked data-kanuni-editor — unless suspendBlurCommit(true) is on. Optional to use.

Parameters

event

FocusEvent

Returns

void


error

error: string | null

Validation message for value, or null.


errorId

errorId: string | undefined

Id of an element holding error while there is one (screen-reader text the grid draws next to the editor) — for aria-errormessage / aria-describedby. Draw the message visibly yourself. Undefined when there is no error.


invalid

invalid: boolean

True while error is set — for aria-invalid.


rawValue

rawValue: unknown

The column's field as stored in the row (pending edits applied), before any valueGetter — the bit set behind a "E;D;S" summary, say. Undefined when the column has no field.


row

row: TRow

The row with pending edits applied — what a cascading list should read.


rowKey

rowKey: RowKey

Key of the edited row.


setValue

setValue: (value) => void

Parameters

value

unknown

Returns

void


suspendBlurCommit

suspendBlurCommit: (on) => void

While on, losing focus is not leaving the editor: commitOnBlur and the commitOn: 'row' send on "focus left the grid" wait. Turn it on before a dialog of the editor takes focus, off when the dialog closes. Ends by itself when the editor closes. No-op in the row form.

Parameters

on

boolean

Returns

void


value

value: unknown

Current (uncommitted) editor value — what the built-in editor would show: the column's valueGetter result when it has one.