useSortBy should toggle`aria-sort` on column headers and relevant demos should encourage a11y best practices
See original GitHub issueDescribe the bug (required)
useSortBy
should leverage thearia-sort
attribute which describes the current sort direction for a particular column to screen reader only users- The demo for
useSortBy
is not keyboard accessible - fortunately this can be overcome easily via manually leveragingcolumn.toggleSortBy
! Since this library is fairly popular, it would be good to encourage best practices where possible.
Provide an example via Codesandbox! (required)
Codesandbox Demo <-- here is a demo demonstrating the lack of aria-sort
on the <th>
elements with a keyboard accessible implementation using column.toggleSortBy
Steps To Reproduce (required)
- Go to the linked demo in the documentation for
useSortBy
- Try to control the sorting using a keyboard only - unfortunately you can’t due to some HTML semantics problems
- When clicking on a
<th>
to sort, inspect the DOM for thearia-sort
attribute - it isn’t set at all.
Expected behavior (Recommended) Here is a great demo of how this should work from a reliable source: https://dequeuniversity.com/library/aria/table-sortable
- All sortable
<th>
elements have a nested<button>
inside to make them keyboard accessible - All sortable
<th>
elements have a validaria-sort
attribute (but only if they are sortable!) - Note they do not have the
title
attribute that is currently provided byuseSortBy
- this shouldn’t be necessary with thearia-sort
attribute in place.
Screenshots N/A
Desktop (please complete the following information):
- OS: macOS Big Sur
- Browser: All browsers
- Version: 7.6.3
Smartphone (please complete the following information):
N/A
Additional context Seriously, thanks to all of the maintainers for your work. The headless approach this library takes serves the React community well.
Depending on the complexity of the code, I could potentially jump in and help out with this one. The aria-sort
problem in particular seems like low-hanging fruit. Updating a CodeSandbox demo should be quite easy as well, though I’m not sure of the best way to go about doing that in this case.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:10
- Comments:12
I’m happy to accept any PRs for better aria attrs!
I agree. And most devs don’t know too much about
aria
and often don’t have the business justification to bother supporting it. In my opinion it should be baked in whenever possible. If adding too many properties by default was a concern there could be some configuration one could set to decide whether or not to generate aria attributes.