Focus ownership and restoration
experimental
A virtualised grid whose logical focus is keyed by row and column ID and mapped to one roving tab stop.
Live example
Expected behavior
Focus persists across sort and refresh. Deleting the focused row moves focus to the next row, or to the previous row at the end. Exactly one cell has tabindex=0 at any time.
Source
const api = createGrid({ rows, columns, getRowId, focusRestoreOnRefresh: true });
api.on('focus:changed', ({ previous, next }) => inspector(next));
api.setFocusedCell({ rowId: '42', columnId: 'name' });
api.getFocusedCell(); // survives sort and setRowsconst api = createGrid({ rows, columns, getRowId, focusRestoreOnRefresh: true });
api.on('focus:changed', ({ previous, next }) => inspector(next));
api.setFocusedCell({ rowId: '42', columnId: 'name' });
api.getFocusedCell(); // survives sort and setRowsconst api = createGrid({ rows, columns, getRowId, focusRestoreOnRefresh: true });
api.on('focus:changed', ({ previous, next }) => inspector(next));
api.setFocusedCell({ rowId: '42', columnId: 'name' });
api.getFocusedCell(); // survives sort and setRowsconst api = createGrid({ rows, columns, getRowId, focusRestoreOnRefresh: true });
api.on('focus:changed', ({ previous, next }) => inspector(next));
api.setFocusedCell({ rowId: '42', columnId: 'name' });
api.getFocusedCell(); // survives sort and setRows// JavaScript interop module
const api = createGrid({ rows, columns, getRowId, focusRestoreOnRefresh: true });
api.on('focus:changed', ({ previous, next }) => inspector(next));
api.setFocusedCell({ rowId: '42', columnId: 'name' });
api.getFocusedCell(); // survives sort and setRowsAPI reference
| Kind | Name | Type | Description |
|---|---|---|---|
| Method | getFocusedCell | — | Returns the logical FocusPosition. |
| Method | setFocusedCell | — | Sets or clears the logical focus without moving DOM focus. |
| Method | focusGrid | — | Ensures a focus position exists and returns it. |
| Event | focus:changed | — | Fires with the previous and next position. |
| Option | focusRestoreOnRefresh | — | Moves focus to a neighbouring row when its row is removed. |