Keyboard-only workflows
Set up a grid that power users and keyboard-only users can drive end to end, from navigation and editing to menus, filters, undo, ranges and the clipboard.
Data-entry teams often never touch the mouse. This recipe configures a grid where every common task has a key, and lists the keys to put in your onboarding notes.
1. Configure the grid#
import { createGrid, type ColumnDef } from '@birchui/core';
import { ClipboardModule, RangeSelectionModule } from '@birchui/grid-pro';
import type { InvoiceLine } from './invoices';
const columns: ColumnDef<InvoiceLine>[] = [
{ field: 'sku', header: 'SKU', width: 120, rowHeader: true },
{ field: 'description', header: 'Description', flex: 1, editable: true, filter: 'text' },
{ field: 'quantity', header: 'Qty', type: 'number', editable: true, filter: 'number' },
{ field: 'unitPrice', header: 'Unit price', type: 'number', editable: true },
{ field: 'taxCode', header: 'Tax', editable: true, editor: 'select', options: ['STD', 'RED', 'ZERO'], filter: 'set' },
];
export const grid = createGrid<InvoiceLine>(document.querySelector<HTMLElement>('#lines')!, {
columns,
rows: lines,
getRowId: (line) => line.sku,
ariaLabel: 'Invoice lines',
undoRedo: true,
modules: [RangeSelectionModule, ClipboardModule],
rangeSelection: true,
clipboard: true,
});
document.addEventListener('keydown', (event) => {
if (event.altKey && event.key === 'g') {
event.preventDefault();
grid.focusCell(0, 'description');
}
});Range selection and the clipboard are Grid Pro features; everything else on this page works in the free package. The Alt+G shortcut is an application-level way to jump into the grid from anywhere on the page.
2. The key map#
On macOS, use Cmd wherever Ctrl is listed.
Moving and editing#
| Keys | Action |
|---|---|
| Arrow keys, Home, End, Page Up, Page Down | Move focus |
| Ctrl+Home / Ctrl+End | First or last cell |
| Enter or F2 | Edit the focused cell |
| Any printable character | Start editing with that character |
| Tab / Shift+Tab while editing | Commit and edit the next or previous editable cell |
| Enter / Escape while editing | Commit or cancel |
| Delete or Backspace | Clear an editable cell |
| Ctrl+Z | Undo (with undoRedo) |
| Ctrl+Y or Ctrl+Shift+Z | Redo |
Menus and filters#
| Keys | Action |
|---|---|
| Shift+F10 or the context menu key on a cell | Open the cell context menu |
| Alt+Arrow Down or the context menu key on a header | Open the column menu |
| Ctrl+Shift+F | Open the filter popup for the focused column |
| Enter or Space on a header | Sort; add Shift for multi-column sort |
| Arrow Up from the first row | Move to the header row |
Inside a menu, arrow keys move between items, Enter runs one and Escape closes the menu and returns focus to the cell.
Ranges and clipboard (Grid Pro)#
| Keys | Action |
|---|---|
| Shift+arrow keys | Extend the range |
| Shift+Ctrl+arrow keys | Extend to the edge of the data |
| Ctrl+A | Select every cell |
| Ctrl+C / Ctrl+X / Ctrl+V | Copy, cut and paste as tab-separated text |
| Escape | Clear the range |
A paste of many cells is one undo step, so Ctrl+Z reverts the whole paste.
3. Add your own keys#
Listen to cellKeyDown for shortcuts that act on the focused row:
grid.on('cellKeyDown', ({ event, row }) => {
if (!(event instanceof KeyboardEvent) || !row) return;
if ((event.ctrlKey || event.metaKey) && event.key === 'd') {
event.preventDefault();
grid.applyTransaction({ add: [{ ...row, sku: nextSku() }] });
}
});Pitfalls#
- Name the grid. Set
ariaLabelso screen reader users know which grid they are in. - Tab leaves the grid when no cell is being edited. That is deliberate: the grid is one tab stop, and arrow keys move inside it.
- Browser shortcuts. Ctrl+Shift+F is free in common browsers, but some screen readers and extensions use it. Mention the column menu, which has a Filter… item, as the alternative.
- Shortcuts are inactive while editing. Inside an editor, Ctrl+Z and Shift+arrows belong to the text input.
Related#
- Accessibility and its full keyboard map.
- Range selection keyboard and Clipboard.
- Editable grid with validation and undo.
- Key handlers for shortcuts inside a module.