Keyboard Navigation for the Column Header
The column header can be used from the keyboard, just like the table cells - you can move between the column headers and the column group headers, sort, open the column menu and get to the column filters without using the mouse.
Press
Tab from the element before the grid, and focus goes to a column header - the one in the first column, or the one that last had focus, when you come back to the header. Clicking a column header also gives it focus, so you can continue with the keyboard from there.- Use
ArrowLeftandArrowRightto go to the previous and next header on the same header row. - Use
HomeandEndto go to the first and the last header on the same header row. - Use
ArrowUpandArrowDownto move between the rows of column groups and the column headers.
- Use
Enterto toggle the sort of the focused column, same as clicking it. WithCtrl/Cmd, the column is added to the current sort, same asCtrl/Cmd+ click (seemultiSortBehavior).Enterdoes nothing on a column group header. - Use
Alt+ArrowDownto open the column menu of the focused column. When the menu closes (Escape, or after picking an item), focus goes back to the column header.
- Use
ArrowDownon a column header to go to its filter editor (when column filters are shown), and from there to the body of the table. - Use
ArrowUpon the first row of the body to go back to the header: to the filter editor of the column, or to the column header when there are no column filters.
When
ArrowDown goes from the header to the body, the cell in the same column on the first visible row becomes the active cell - or, with keyboardNavigation="row", the first visible row becomes the active row.The keys in the header work whatever the value of
keyboardNavigation - but with keyboardNavigation={false}, there is no active cell or row in the body, so ArrowUp from the body doesn't go to the header.Tab order#
Tab and Shift+Tab go through the header in the order the columns are shown (pinned columns included): each column header, followed by its filter editor, when column filters are shown.Tabfrom the last column (or from its filter editor) goes to the body of the table.Shift+Tabfrom the body goes to the last column of the header - to its filter editor, when it has one.Shift+Tabfrom the first column header goes to the element before the grid.
Column group headers are not
Tab stops - use ArrowUp to reach them.Keys in filter editors#
In a filter editor, the keys belong to the editor -
ArrowLeft and ArrowRight move the caret in a text input, for example. Only a few keys take you out of the editor:ArrowUpgoes to the column header.ArrowDowngoes to the body of the table.Tabgoes to the next column header, andShift+Tabback to the column header of the filter. In a filter editor with several inputs (for example a range),TabandShift+Tabfirst move between its own inputs.
If a custom filter editor needs
ArrowUp or ArrowDown itself (for example to change a value or to open a list), call event.preventDefault() in its keydown handler, and the grid leaves the key to the editor.Reordering columns#
A focused column header keeps focus when you drag it to a new position, so you can continue with the keyboard from its new place.
Preventing header navigation#
Return
{ preventNavigation: true } from onKeyDown to stop the grid from handling a key, in the header as well as in the body.Theming#
A column header (or column group header) focused from the keyboard gets the same background as the active cell in the body, so the CSS variables in the cell navigation theming section change it too - for example
--infinite-active-cell-background, or the --infinite-active-cell-border-color--r / --g / --b variables.The focused header also gets a className, which you can use to style it in your own way:
InfiniteHeaderCell--focusedfor a column headerInfiniteHeaderGroup--focusedfor a column group header
The background is shown only for keyboard focus (it uses
:focus-visible), while the classNames are set for any focus, including after a click on the header.