-
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Description
Describe 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.