Keyboard Navigation for the Column Header

View as Markdown
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.
#
Navigating the column header
Click the button above the grid and press Tab to focus the header. Then use the arrow keys to move around, Enter to sort, Alt+ArrowDown to open the column menu and Tab to go to the column filters.
open
loading demo…
  • Use ArrowLeft and ArrowRight to go to the previous and next header on the same header row.
  • Use Home and End to go to the first and the last header on the same header row.
  • Use ArrowUp and ArrowDown to move between the rows of column groups and the column headers.

  • Use Enter to toggle the sort of the focused column, same as clicking it. With Ctrl / Cmd, the column is added to the current sort, same as Ctrl / Cmd + click (see multiSortBehavior). Enter does nothing on a column group header.
  • Use Alt+ArrowDown to 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 ArrowDown on a column header to go to its filter editor (when column filters are shown), and from there to the body of the table.
  • Use ArrowUp on 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.
  • Tab from the last column (or from its filter editor) goes to the body of the table.
  • Shift+Tab from the body goes to the last column of the header - to its filter editor, when it has one.
  • Shift+Tab from 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:
  • ArrowUp goes to the column header.
  • ArrowDown goes to the body of the table.
  • Tab goes to the next column header, and Shift+Tab back to the column header of the filter. In a filter editor with several inputs (for example a range), Tab and Shift+Tab first 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--focused for a column header
  • InfiniteHeaderGroup--focused for 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.