fix(Table): Add keyboard support to table sorting#5736
Conversation
|
The keyboard navigation looks good to me: there's focus states, chevrons indicate sorting, hitting space works. There is a bug: I've played a bit with it and sorting seems to be alphabetical; it should be smart enough to detect numbers so in those cases it sorts from higher to lower (instead of "1, 10, 12, 140, 2, 20, 3"). Happy to help test this. |
@juanruitina I agree - though I believe this warrants a separate issue focusing on the sorting logic itself, rather than the keyboard accessibility. Can you file an issue? |
|
LGTM. I was going to change what the focus state for a table header in terms of sorting is going to look like in the new table that I was designing which you can find here: https://www.figma.com/design/2MYJvamCVgbyWXZRT7IPan/25.10-Data-table---Design-system-contributions?node-id=4351-96714&t=1oohgcxOtOvarVUn-4. |
bartaz
left a comment
There was a problem hiding this comment.
Some small comments inline in code, but overall looks good. Thanks!
There was a problem hiding this comment.
Pull request overview
This PR adds keyboard accessibility to sortable table headers by wrapping header text in <button> elements, following W3C guidelines. This enables users to sort tables using Enter and Space keys.
Changes:
- Wrapped sortable table header text in
<button class="p-table__sort-button">elements - Added SCSS styles to make buttons appear as seamless part of headers
- Created legacy example to maintain backward compatibility
- Updated documentation to explain the new keyboard-accessible markup
- Incremented version from 4.39.0 to 4.39.1
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
scss/_patterns_table-sortable.scss |
Added styles for the new .p-table__sort-button class and adjusted hover/focus states |
templates/docs/examples/patterns/tables/_table-sortable.html |
Updated example to wrap header text in buttons |
templates/docs/examples/patterns/tables/table-sortable-legacy.html |
Added legacy example without keyboard support for backward compatibility |
templates/docs/examples/patterns/tables/combined.html |
Included legacy example in combined examples |
templates/docs/base/tables.md |
Added documentation about keyboard sorting with updated status badge |
releases.yml |
Added 4.39.1 release notes |
package.json |
Bumped version to 4.39.1 |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
bump
rm unnecessary button height rm unnescessary align-items
4b08af8 to
9696046
Compare
Done
Makes sortable table headers keyboard-accessible by wrapping the text in button elements. Follows w3c example which recommends wrapping the header text in a button, inside the th.
Fixes https://warthogs.atlassian.net/browse/WD-32943
Fixes #5735
React Components will require an update (updating the table headers markup) to benefit from this fix.
QA
Design
buttonelement for proper interactivity semantics, but this carries with it the default button styling. I made the table sort button inherit the table header label's styling to negate this, but have a look and make sure I didn't miss anything.Check if PR is ready for release
If this PR contains Vanilla SCSS or macro code changes, it should contain the following changes to make sure it's ready for the release:
Feature 🎁,Breaking Change 💣,Bug 🐛,Documentation 📝,Maintenance 🔨.package.jsonshould be updated relative to the most recent release, following semver convention