# 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

```ts title="invoice-lines-grid.ts"
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 <kbd>Alt</kbd>+<kbd>G</kbd> shortcut is an application-level way to jump into the grid from anywhere on the page.

## 2. The key map

On macOS, use <kbd>Cmd</kbd> wherever <kbd>Ctrl</kbd> is listed.

### Moving and editing

| Keys | Action |
| --- | --- |
| Arrow keys, <kbd>Home</kbd>, <kbd>End</kbd>, <kbd>Page Up</kbd>, <kbd>Page Down</kbd> | Move focus |
| <kbd>Ctrl</kbd>+<kbd>Home</kbd> / <kbd>Ctrl</kbd>+<kbd>End</kbd> | First or last cell |
| <kbd>Enter</kbd> or <kbd>F2</kbd> | Edit the focused cell |
| Any printable character | Start editing with that character |
| <kbd>Tab</kbd> / <kbd>Shift</kbd>+<kbd>Tab</kbd> while editing | Commit and edit the next or previous editable cell |
| <kbd>Enter</kbd> / <kbd>Escape</kbd> while editing | Commit or cancel |
| <kbd>Delete</kbd> or <kbd>Backspace</kbd> | Clear an editable cell |
| <kbd>Ctrl</kbd>+<kbd>Z</kbd> | Undo (with `undoRedo`) |
| <kbd>Ctrl</kbd>+<kbd>Y</kbd> or <kbd>Ctrl</kbd>+<kbd>Shift</kbd>+<kbd>Z</kbd> | Redo |

### Menus and filters

| Keys | Action |
| --- | --- |
| <kbd>Shift</kbd>+<kbd>F10</kbd> or the context menu key on a cell | Open the cell [context menu](https://docs.birchui.com/recipes/grid-context-menu.md) |
| <kbd>Alt</kbd>+<kbd>Arrow Down</kbd> or the context menu key on a header | Open the column menu |
| <kbd>Ctrl</kbd>+<kbd>Shift</kbd>+<kbd>F</kbd> | Open the filter popup for the focused column |
| <kbd>Enter</kbd> or <kbd>Space</kbd> on a header | Sort; add <kbd>Shift</kbd> for multi-column sort |
| <kbd>Arrow Up</kbd> from the first row | Move to the header row |

Inside a menu, arrow keys move between items, <kbd>Enter</kbd> runs one and <kbd>Escape</kbd> closes the menu and returns focus to the cell.

### Ranges and clipboard (Grid Pro)

| Keys | Action |
| --- | --- |
| <kbd>Shift</kbd>+arrow keys | Extend the range |
| <kbd>Shift</kbd>+<kbd>Ctrl</kbd>+arrow keys | Extend to the edge of the data |
| <kbd>Ctrl</kbd>+<kbd>A</kbd> | Select every cell |
| <kbd>Ctrl</kbd>+<kbd>C</kbd> / <kbd>Ctrl</kbd>+<kbd>X</kbd> / <kbd>Ctrl</kbd>+<kbd>V</kbd> | Copy, cut and paste as tab-separated text |
| <kbd>Escape</kbd> | Clear the range |

A paste of many cells is one undo step, so <kbd>Ctrl</kbd>+<kbd>Z</kbd> reverts the whole paste.

## 3. Add your own keys

Listen to `cellKeyDown` for shortcuts that act on the focused row:

```ts
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 `ariaLabel` so 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.** <kbd>Ctrl</kbd>+<kbd>Shift</kbd>+<kbd>F</kbd> 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, <kbd>Ctrl</kbd>+<kbd>Z</kbd> and <kbd>Shift</kbd>+arrows belong to the text input.

## Related

- [Accessibility](https://docs.birchui.com/grid/accessibility.md) and its full [keyboard map](https://docs.birchui.com/grid/accessibility.md#keyboard-map).
- [Range selection keyboard](https://docs.birchui.com/grid-pro/range-selection.md#keyboard) and [Clipboard](https://docs.birchui.com/grid-pro/clipboard.md).
- [Editable grid with validation and undo](https://docs.birchui.com/recipes/grid-editing-validation-undo.md).
- [Key handlers](https://docs.birchui.com/grid/modules.md#key-handlers) for shortcuts inside a module.
