Keyboard Navigation
NextGrid routes keyboard events from its composite navigation root across body cells, headers, pinned regions, menus, active editors, and nested detail grids.
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(); };}Shortcuts by Context
Section titled “Shortcuts by Context”| Context | Keys | Action | Notes |
|---|---|---|---|
| Body & Regions | Arrow keys | Move cell focus by one row or column | Left/Right flip logically in RTL |
| Body & Regions | Home / End | Move focus to first / last visible column in row | — |
| Body & Regions | Ctrl/Cmd + Home / End | Move focus to first / last cell in grid | — |
| Body & Regions | PageUp / PageDown | Scroll and move focus by one viewport page | — |
| Body & Regions | Shift + Arrow / Home / End / PageUp / PageDown | Extend cell range selection (when cellSelection.mode is "range") | — |
| Body & Rows | Space | Toggle row selection (when rowSelection is enabled) | — |
| Body & Hierarchy | Enter / Space (on group toggle) | Expand or collapse group or tree node | — |
| Body & Detail | Enter / Space (on detail toggle) | Expand or collapse detail row; Tab moves into nested grid | — |
| Header | Enter / Space | Sort column (Shift + Enter adds multi-column sort) | — |
| Header | Shift + F10 / Alt + ArrowDown / ContextMenu | Open header column menu | — |
| Body Context Menu | Shift + F10 / ContextMenu | Open body context menu at focused cell/row | — |
| Menu Popup | ArrowUp / ArrowDown / Home / End | Navigate menu items (skips separators and disabled items) | — |
| Menu Popup | Enter / Space / Escape | Activate item or close menu and restore focus | — |
| Editing | Enter / F2 / printable key | Start editing focused editable cell | — |
| Editing | Enter / Tab / Shift + Tab | Commit edit (Tab moves focus to next/previous cell) | — |
| Editing | Ctrl/Cmd + Enter (in textarea) | Commit multiline textarea edit (Enter inserts newline) | — |
| Editing | Escape | Cancel edit and restore original cell value | — |
| Clipboard & History | Ctrl/Cmd + C / X / V | Copy, cut, or paste TSV selection | — |
| Clipboard & History | Delete / Backspace | Clear editable selected/focused cells | — |
| Clipboard & History | Ctrl/Cmd + Z / Y (or Shift + Z) | Undo / Redo edit, paste, cut, delete, or fill batch | — |
RTL & Platform Notes
Section titled “RTL & Platform Notes”- RTL (
direction: 'rtl'):ArrowLeftandArrowRightmove in visual screen direction (soArrowLeftadvances toward higher column indices in RTL). - macOS vs. Windows/Linux: Clipboard and history shortcuts (
C,X,V,Z,Y,Home,End,Enterin<textarea>) accept eitherCtrlorCmd(metaKey). - IME Composition: Keyboard navigation and quick-start editing ignore events while
isComposingistrue(keyCode === 229).