Keyboard Navigation
OGrid supports comprehensive keyboard navigation for moving between cells, editing values, selecting ranges, and performing clipboard and undo operations -- all without touching the mouse.
Live Demo
The demo above uses Radix UI for styling. To see this feature with the Fluent UI implementation, click "Open in online demo" below the demo.
Quick Example
- React
import { OGrid } from '@alaarab/ogrid-react-radix';
function App() {
return (
<OGrid
columns={columns}
data={data}
getRowId={(r) => r.id}
editable
/>
);
}
The OGrid component has the same props across all React UI packages. To switch, just change the import:
- Radix (lightweight, default):
from '@alaarab/ogrid-react-radix' - Fluent UI (Microsoft 365 / SPFx):
from '@alaarab/ogrid-react-fluent'- wrap in<FluentProvider>
Click any cell, or Tab into the grid, to make it the active cell, then use the keyboard to navigate and edit.
The active cell holds real keyboard focus (a roving tabindex): it is the grid's only tab stop, and focus moves with it as you navigate, so screen readers announce each cell. See Accessibility: focus model.
Navigation
| Key | Action |
|---|---|
| Arrow Up / Down / Left / Right | Move active cell in that direction |
| Ctrl+Arrow | Jump to the edge of the current data region (Excel-style) |
| Tab | Move to the next cell (left to right, then next row). From the last cell, Tab moves focus out of the grid |
| Shift+Tab | Move to the previous cell. From the first cell, Shift+Tab moves focus out of the grid |
| Shift+Enter | Move up one cell (Enter on a single cell starts editing) |
| Home | Move to the first column in the current row |
| End | Move to the last column in the current row |
| Ctrl+Home | Move to the first cell in the grid (top-left) |
| Ctrl+End | Move to the last cell in the grid (bottom-right) |
| Page Down | Move down by one page of rows |
| Page Up | Move up by one page of rows |
Cell Selection
| Key | Action |
|---|---|
| Click | Set active cell |
| Shift+Arrow | Extend selection range from the active cell (the active cell stays put as the anchor) |
| Ctrl+Shift+Arrow | Extend selection to the edge of the current data region |
| Shift+Home / Shift+End | Extend selection from the active cell to the first / last column of the row |
| Ctrl+Shift+Home / Ctrl+Shift+End | Extend selection from the active cell to the first / last cell of the grid |
| Shift+Click | Select range from active cell to clicked cell |
| Ctrl+Space | Select the whole column(s) the selection covers |
| Shift+Space | Without row selection: select the whole row(s) the selection covers. With rowSelection: toggle the active cell's row (unchanged) |
| Ctrl+Shift+Space | Select all cells |
| Click a column letter / row number | Select the whole column / row (with cellReferences); Shift+click or drag across headers extends |
| ← from the first column | Move to the row's checkbox cell (rowSelection="multiple") |
| Space on the checkbox cell | Toggle that row |
| Shift+Space on the checkbox cell | Select the rows from the last toggled row to this one |
| Space on an editable boolean cell | Toggle the checkbox |
| Ctrl+A | Select all cells in the grid (for copy/paste/fill operations, not row selection) |
The selection range is highlighted with a green border. The active cell remains visually distinct within the range.
Whole-row and whole-column selections are ordinary cell ranges: copy, Delete, fill (Ctrl+D / Ctrl+R) and the status bar aggregates all work on them. When the selection touches a merged cell it grows to include the whole merge, and the active cell always sits on a merge's top-left (anchor) cell.
Moving inside a selection
With more than one cell selected, Enter and Tab move the active cell through the selection instead of collapsing it, like Excel. Enter goes down a column and on to the top of the next one; Tab goes across a row and on to the start of the next one. Both wrap from the last cell back to the first, Shift reverses them, and cells covered by a merge are skipped. This also applies when you commit an edit with Enter or Tab, so you can select a block and type values into it one after another.
Ctrl+A selects all cells in the grid for spreadsheet operations (copy/paste/fill). This is different from row selection, where the header checkbox selects all rows for bulk operations. See Row Selection and Spreadsheet Selection for details.
Ctrl+Arrow (Data Region Jump)
Ctrl+Arrow navigates the same way Excel does:
- Non-empty cell to non-empty neighbor: Jumps to the last non-empty cell before a gap (empty cell) or the grid edge.
- Non-empty cell to empty neighbor: Skips over the empty cells and lands on the next non-empty cell, or the grid edge if all remaining cells are empty.
- Empty cell: Jumps to the next non-empty cell in that direction, or the grid edge.
Combine with Shift to extend the selection range to the same target.
Editing
| Key | Action |
|---|---|
| Enter | Start editing the active cell; press again to commit and move down |
| F2 | Start editing the active cell (cursor at end of text) |
| Escape | Cancel editing and revert to the original value |
| Delete / Backspace | Clear the contents of selected cells |
| Any printable character | Start editing and replace cell content with the typed character |
| Ctrl+D | Fill down: copy the top row of the selection into the rows below |
| Ctrl+R | Fill right: copy the left column of the selection into the columns to its right |
| Ctrl+; | Enter today's date into the active cell |
| Ctrl+Shift+; | Enter the current time (HH:mm, 24-hour) into the active cell |
When a cell is in edit mode:
- Enter commits the value and moves the active cell down; Shift+Enter commits and moves up.
- Tab commits the value and moves the active cell right.
- F4 in a formula (text starting with
=) cycles the reference at or just before the caret:A1→$A$1→A$1→$A1→A1. Both ends of a range (A1:B2) change together. F4 works the same way in the formula bar. - Formula autocomplete (with
formulason): while the function list is open, Up/Down move, Tab or Enter inserts the function, and Escape closes the list. With the list closed, Enter, Tab and Escape behave as usual. See Formulas. - Escape discards the edit and returns to navigation mode.
- Arrow keys move the cursor within the editor (they do not navigate between cells while editing).
Typing over a cell
Typing a character on a selected cell opens its editor with that character in place of the old value, as in Excel. It works for text, number and date cells, and through the column's valueParser on commit. Keys held with Ctrl, Cmd or Alt are shortcuts and never start an edit (AltGr characters still type). Space keeps its own bindings (toggling a boolean cell or the row selection), and Enter/F2 open the editor with the existing value.
| Cell editor | Typing a character |
|---|---|
| Text, date (and untyped columns) | Opens with the character replacing the value |
richSelect | Opens with the character as the search text |
select | Opens the dropdown |
checkbox / type: 'boolean' | Nothing (Space toggles it) |
Custom popover editor (cellEditor component) | Opens with the current value (the editor's value type may not be text) |
With an input method editor (IME) active, the first keystroke opens an empty editor and composition continues in it.
Dates and times
Ctrl+; writes today's date (from the local clock) into the active cell without opening the editor. Date columns (type: 'date' or the date editor) get YYYY-MM-DD, which is what the date editor stores; other columns get the date in the column's dateFormat (YYYY-MM-DD by default). Ctrl+Shift+; writes the time as HH:mm. The value goes through the column's valueParser, so a column that rejects it (a number column, for example) is left unchanged. Each is one undo step.
Clipboard
| Key | Action |
|---|---|
| Ctrl+C | Copy selected cells to clipboard (tab-separated) |
| Ctrl+X | Cut selected cells (copy + clear originals) |
| Ctrl+V | Paste clipboard contents starting at the active cell (repeated over a larger selection that is an exact multiple of it) |
| Ctrl+Shift+V | Paste values only: computed values, never formulas |
Copied data uses tab-separated format compatible with Excel and Google Sheets. Multi-cell selections copy the entire rectangular range.
Undo / Redo
| Key | Action |
|---|---|
| Ctrl+Z | Undo the last cell edit |
| Ctrl+Y | Redo the last undone edit |
Undo/redo requires the onUndo, onRedo, canUndo, and canRedo props to be wired up (typically via the useUndoRedo hook).
Keyboard Resizing
Each column's resize handle is a focusable role="separator" (Tab to it from the header). While it has focus:
| Key | Action |
|---|---|
| Arrow Right / Arrow Left | Widen / narrow the column by 10px |
| Shift+Arrow Right / Shift+Arrow Left | Widen / narrow the column by 1px |
| Home | Shrink the column to its minimum width |
| Enter | Keep the new width and return focus to the grid |
| Escape | Restore the width the column had when the handle received focus |
Keyboard resizing uses the same state path as dragging: onColumnResized fires on every step, the width shows up in getColumnState(), and controlled column state and persistence see it. The column's minWidth is respected.
How It Works
Keyboard navigation is handled by the useKeyboardNavigation hook in core, which is automatically wired into the grid when cellSelection is enabled (the default). The hook listens for keydown events on the grid wrapper element and translates them into active cell movements, selection range changes, or editing actions.
Disabling Cell Selection
Set cellSelection={false} to disable keyboard-driven cell navigation, selection, clipboard, and context menu. The grid becomes a read-only display table.
<OGrid
columns={columns}
data={data}
getRowId={(r) => r.id}
cellSelection={false}
/>
macOS
On macOS, Ctrl is replaced by the Command key for all shortcuts (Cmd+C, Cmd+V, Cmd+Z, etc.). The grid detects the platform automatically.
Props Reference
| Type | Field | Description |
|---|---|---|
IOGridProps<T> | cellSelection | boolean -- enable/disable keyboard navigation and selection (default true) |
IOGridProps<T> | editable | boolean -- enable cell editing via keyboard |
IOGridProps<T> | onUndo | Callback for Ctrl+Z |
IOGridProps<T> | onRedo | Callback for Ctrl+Y |
IOGridProps<T> | canUndo | boolean -- whether undo is available |
IOGridProps<T> | canRedo | boolean -- whether redo is available |
Related
- Context Menu -- right-click menu mirrors keyboard shortcuts
- Status Bar -- shows aggregations for keyboard-selected ranges
- Column Pinning -- navigation works seamlessly across pinned and scrollable columns
useGridFocus-- headless Arrow / Tab / Enter / Home / End / PageUp / PageDown navigation for your own table