WarUI documentation

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 setRows

API reference

GRID-A01-F22 API
KindNameTypeDescription
MethodgetFocusedCell—Returns the logical FocusPosition.
MethodsetFocusedCell—Sets or clears the logical focus without moving DOM focus.
MethodfocusGrid—Ensures a focus position exists and returns it.
Eventfocus:changed—Fires with the previous and next position.
OptionfocusRestoreOnRefresh—Moves focus to a neighbouring row when its row is removed.