Skip to content

Keyboard Navigation

NextGrid routes keyboard events from its composite navigation root across body cells, headers, pinned regions, menus, active editors, and nested detail grids.

Interactive Keyboard Navigation
import { Grid, type ColumnDef } from 'next-grid-js';
import { createOrders, type OrderRow } from './data/orders';
import { syncGridTheme } from './theme';
import type { DemoMountContext } from './types';
import { addButton } from './ui';
export function mount({
stage,
controls,
meta,
}: DemoMountContext): () => void {
const columnDefs: readonly ColumnDef<OrderRow>[] = [
{
key: 'id',
name: 'ID',
width: 96,
isSortable: true,
},
{
key: 'customer',
name: 'Customer',
width: 175,
flex: 1,
isSortable: true,
},
{
key: 'region',
name: 'Region',
width: 105,
isSortable: true,
},
{
key: 'quantity',
name: 'Qty',
width: 80,
cellDataType: 'number',
isEditable: true,
},
{
key: 'status',
name: 'Status',
width: 105,
},
];
const grid = new Grid<OrderRow>({
container: stage,
ariaLabel: 'Keyboard navigation demo',
columnDefs,
rowData: createOrders(40),
getRowId: (row) => row.id,
rowSelection: {
mode: 'multiple',
showCheckbox: true,
},
cellSelection: { mode: 'range' },
});
const stopTheme = syncGridTheme(stage);
grid.addEventListener('focusChanged', ({ focus }) => {
if (!focus) {
meta.textContent = 'Focus: none';
} else if (focus.kind === 'cell') {
meta.textContent = `Cell row ${focus.displayIndex} · ${focus.colId}`;
} else if (focus.kind === 'header') {
meta.textContent = `Header · ${focus.colId}`;
} else {
meta.textContent = `Focus: ${focus.kind}`;
}
});
addButton(controls, 'Focus row 15', () => {
grid.setFocusedCell(
{
row: { displayIndex: 15 },
colId: 'customer',
},
{
focusDom: true,
ensureVisible: true,
},
);
});
meta.textContent =
'Click a cell and use Arrows, Home/End, PageUp/Down, Space, or Enter';
return () => {
grid.destroy();
stopTheme();
};
}
ContextKeysActionNotes
Body & RegionsArrow keysMove cell focus by one row or columnLeft/Right flip logically in RTL
Body & RegionsHome / EndMove focus to first / last visible column in row—
Body & RegionsCtrl/Cmd + Home / EndMove focus to first / last cell in grid—
Body & RegionsPageUp / PageDownScroll and move focus by one viewport page—
Body & RegionsShift + Arrow / Home / End / PageUp / PageDownExtend cell range selection (when cellSelection.mode is "range")—
Body & RowsSpaceToggle row selection (when rowSelection is enabled)—
Body & HierarchyEnter / Space (on group toggle)Expand or collapse group or tree node—
Body & DetailEnter / Space (on detail toggle)Expand or collapse detail row; Tab moves into nested grid—
HeaderEnter / SpaceSort column (Shift + Enter adds multi-column sort)—
HeaderShift + F10 / Alt + ArrowDown / ContextMenuOpen header column menu—
Body Context MenuShift + F10 / ContextMenuOpen body context menu at focused cell/row—
Menu PopupArrowUp / ArrowDown / Home / EndNavigate menu items (skips separators and disabled items)—
Menu PopupEnter / Space / EscapeActivate item or close menu and restore focus—
EditingEnter / F2 / printable keyStart editing focused editable cell—
EditingEnter / Tab / Shift + TabCommit edit (Tab moves focus to next/previous cell)—
EditingCtrl/Cmd + Enter (in textarea)Commit multiline textarea edit (Enter inserts newline)—
EditingEscapeCancel edit and restore original cell value—
Clipboard & HistoryCtrl/Cmd + C / X / VCopy, cut, or paste TSV selection—
Clipboard & HistoryDelete / BackspaceClear editable selected/focused cells—
Clipboard & HistoryCtrl/Cmd + Z / Y (or Shift + Z)Undo / Redo edit, paste, cut, delete, or fill batch—
  • RTL (direction: 'rtl'): ArrowLeft and ArrowRight move in visual screen direction (so ArrowLeft advances toward higher column indices in RTL).
  • macOS vs. Windows/Linux: Clipboard and history shortcuts (C, X, V, Z, Y, Home, End, Enter in <textarea>) accept either Ctrl or Cmd (metaKey).
  • IME Composition: Keyboard navigation and quick-start editing ignore events while isComposing is true (keyCode === 229).