This repository has been archived by the owner on Jun 5, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
feat: New component SelectableTable, #143 #145
Merged
Merged
Conversation
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
Instead of an extra data-selectable attribute, we now correctly apply the aria-selected attribute to any selectable table rows, and give it an appropriate value.
diondiondion
commented
Jul 21, 2021
@@ -66,6 +68,7 @@ | |||
"prop-types": "^15.7.2", | |||
"react": "^17.0.0", | |||
"react-dom": "^17.0.0", | |||
"regenerator-runtime": "^0.13.7", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had to add this and babel-jest
to be able to run async test functions (e.g. await screen.findByRole(...)
). It seems like normally this shouldn't be necessary, but I couldn't find another way. Would be good to look into that later.
🎉 This PR is included in version 13.3.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Adds a new
SelectionTable
component that supports a roving tab index, table row multi and range selection, and advanced keyboard navigation.Feature-wise it should now be ready to replace the hub's admin main tables on any pages that don't require drag-and-drop table row ordering, subheaders/subsections, or table rows that are non-selectable.
This is a very large PR, and also includes tests for the component, as well as new supplementary components and hooks.
Overview
The following is an excerpt from the revised
Table
readme, it should give a good overview of the new props and functionality.Table row selection
You can make the rows of your table selectable. To do this, use the
SelectionTable
component instead of the regularTable
component:SelectionTable props
The
SelectionTable
component is identical to the regularTable
component, but has some extra props to facilitate selection. Its selection state is controlled, meaning that you have to pass in the selected items and a function to update it in response to changes. The keyboard navigation & highlighting state however is owned bySelectionTable
and can't be controlled from the outside.getItemLabel
-func
: A function that's called with a row object and must return a human-readable string that identifies the row.selectedItems
-string[] | number[]
: An array of the keys/ids of all currently selected items. The keys must match those obtained using thekeyBy
prop (data.item[keyBy]
).onChangeSelectedItems
-func
: Function that's called whenever the table selection changes. It's called with an array of all selected items in the shape of theselectedItems
prop.The
SelectionTable
component also has additional accessibility labels. Those are detailed in the Customise accessibility labels section below.SelectionTable navigation and keyboard shortcuts
You can click anywhere on a row to select it and de-select all other rows, or click the checkboxes to add or remove rows from the selection.
Hold Cmd (Mac) or Ctrl (Windows) while clicking anywhere on a row to select or deselect it. Hold Shift while clicking on a row to select all rows between the row you clicked and the one you clicked before.
SelectionTable
also allows navigating the rows of your table via keyboard:Interactive nested content
Because you can click anywhere on a table row to select it, you need to wrap any interactive elements that you want to render in the table with the
InteractiveTableContent
component. This will make sure that the nested elements can be interacted with without interfering with table selection.Note how the "Open" button in the "Name" column below is wrapped with
InteractiveTableContent
, and clicking it will not change the selected table row.