-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add keyboard navigation to table (#2172)
# Pull Request ## π€¨ Rationale Resolves #1137 ## π©βπ» Implementation See #2173 for the most up-to-date expected behavior of keyboard navigation that this PR implements. ([Direct link to updated HLD](https://github.com/ni/nimble/blob/96e1725fc7cc8b3fdf5f5197b090e8f95f86cd5f/packages/nimble-components/src/table/specs/table-keyboard-navigation-hld.md)) The `KeyboardNavigationManager` class does the bulk of the work: - Tracks what is currently focused / should be focused (via properties `focusType`, and `row/column/cellContent/headerActionIndex`) - Note: If the user clicks in the table away from the current keyboard focus, the focus state would end up out-of-date. There's code in `handleFocus()` to handle this (see additional comments there) - Listens for table keypresses to handle arrow key navigation, Tab/Shift-Tab, PgUp/PgDn/etc key presses - If the user unfocuses and refocuses the table, re-focuses the appropriate elements in the table (`handleFocus()` again) - Tab/Shift-Tab behavior should match the HLD / expectations for ARIA treegrid. (Basically, Tab/Shift-Tab go through the tabbable elements of the header row / current row, not including cells/column headers, until the end is reached, then the table blurs and elements before/after it will be focused with additional Tab presses.) The overall approach of only setting `tabindex=0` on the single element in the table we want focused is called [roving tabindex](https://www.freecodecamp.org/news/html-roving-tabindex-attribute-explained-with-examples/). To ensure that we control what elements in the table should get focused, this PR updates `tabindex` on many elements in the table: - The table itself is `tabindex=0` to ensure that it can be focused via `Tab` - Elements that are focusable by default such as buttons/anchors, are explicitly set to `tabindex=-1` to start with, until the keyboard navigation code wants to focus them (then they're set to `tabindex=0` just before being focused). ## π§ͺ Testing - Manual testing (mostly Chrome, some Firefox). - Earlier builds had some Safari testing, but we should explicitly re-test there before submission. - Added autotests Keyboard navigation can be used on any/all of the [existing table Storybook pages](https://60e89457a987cf003efc0a5b-gjoayfsquj.chromatic.com/?path=/story/components-table--table), once the table is focused. ## β Checklist - [x] I have updated the project documentation to reflect my changes or determined no changes are needed. - Added keyboard nav docs to [table Storybook docs page](https://60e89457a987cf003efc0a5b-gjoayfsquj.chromatic.com/?path=/docs/components-table--docs) (in Accessibility section)
- Loading branch information
Showing
35 changed files
with
3,641 additions
and
97 deletions.
There are no files selected for viewing
7 changes: 7 additions & 0 deletions
7
change/@ni-nimble-components-df1cc26c-9976-477a-8fa0-f9b72492eaa0.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"type": "minor", | ||
"comment": "Add keyboard navigation functionality to the table component", | ||
"packageName": "@ni/nimble-components", | ||
"email": "[email protected]", | ||
"dependentChangeType": "patch" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.