-
Notifications
You must be signed in to change notification settings - Fork 89
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve a11y support for table sorting #1144
base: develop
Are you sure you want to change the base?
Conversation
✅ Deploy Preview for stacks ready!
To edit notification comments on pull requests, go to your Netlify site settings. |
I like it! The only issue I see is with the naming of
My vote is for the warning to stay. Tables (both the HTML element and our component) are convoluted enough that I'm in favor of almost any opportunity to unify the expected markup.
BTW, this is a killer enhancement. You da best 💛 |
To add to what @dancormier said I think this PR is a great step in the right direction to make our tables more accessible. Here are some things I noticed browsing through the feature:
I believe as a next step someone from the core Stacks team should pick this item up and do a thorough review (potentially even pair with you). How urgent is this a11y fix for you and your team @allejo? Thanks again for initiating this! 💛 |
Oh man, that's what I get for not noticing where Git is pushing my branches to 😅 I've deleted the branch that I pushed to the Stacks repo and will keep the one in my fork solely because I don't want the conversations going on here to be lost due (or behind an extra link/click)
I definitely agree with getting designers' eyes on this! I have no objections to moving that functionality out to a separate PR.
Oops! Fixed 😄
You have my attention about a "codemod" tool, what are you envisioning? I'm not fond of updating legacy markup at runtime each time but didn't have any better ideas that wouldn't require some more involved dev work. And you're right about not shipping dev bundles... Completely forgot about that; the runtime warning wouldn't even exist in the dist used in pubplat.
💯 agree! I tried my best to not touch any of the sorting algorithm logic in this PR. But I would have been a lot more comfortable if I could have tests to lean on to check my work and adding new tests for button actions.
I'm cool with this! 😄
Not urgent at the moment. I was working on redesigning some mod pages (that have already been shipped) that had tables and this a11y bug grabbed my attention so I picked it up. |
@allejo I added your PR in our internal team backlog for visibility (you are tagged there too). It would be helpful if you could move the I additionally converted the PR as draft for now too until it's in a better state to be merged. Thanks again for your work. 💛 |
Of course! I have removed the column highlighting functionality from this PR and moved it over to #1165 |
I'm really excited by this change! We'll be wanting sortable tables in an internal project and having sorting be keyboard and screen-reader accessible would be a great thing. Here's another link for reference: https://adrianroselli.com/2021/04/sortable-table-columns.html. It's marked out-of-scope for this PR but this link also presents various different ways to have sortability and sort change to be announced for screen readers. If we do enhance the feature with instructions/announcements here or in future, the HTML will need to provide localised/translated strings for these. I think we should update the documentation in this PR to ensure devs write in the initial Something like this for example: --- a/docs/product/components/tables.html
+++ b/docs/product/components/tables.html
@@ -634,14 +634,14 @@ description: Tables are used to list all information from a data set. The base s
<section class="stacks-section">
{% header "h2", "Sortable tables" %}
<p class="stacks-copy">To indicate that the user can sort a table by different columns, add the <code class="stacks-code">s-table__sortable</code> class to the table.</p>
- <p class="stacks-copy">The <code class="stacks-code"><th></code> cells should include arrows to indicate sortability or the currently applied sorting. In addition, the column that is currently sorted should be indicated with the <code class="stacks-code">is-sorted</code> class on its <code class="stacks-code"><th></code>.</p>
+ <p class="stacks-copy">The <code class="stacks-code"><th></code> cells should include arrows to indicate sortability or the currently applied sorting. In addition, the column that is currently sorted should be indicated with the <code class="stacks-code">is-sorted</code> class and the <code class="stacks-code">aria-sort</code> attribute with the <a href="https://www.w3.org/TR/wai-aria-1.1/#aria-sort">appropriate value</a> on its <code class="stacks-code"><th></code>.</p>
<div class="stacks-preview">
{% highlight html %}
<div class="s-table-container">
<table class="s-table s-table__sortable">
<thead>
<tr>
- <th scope="col" class="is-sorted">Listing @Svg.ArrowDownSm</th>
+ <th scope="col" class="is-sorted" aria-sort="descending">Listing @Svg.ArrowDownSm</th>
<th scope="col">Status @Svg.ArrowUpDownSm</th>
<th scope="col">Owner @Svg.ArrowUpDownSm</th>
<th scope="col" class="ta-right">Views @Svg.ArrowUpDownSm</th>
@@ -659,7 +659,7 @@ description: Tables are used to list all information from a data set. The base s
<table class="s-table s-table__sortable">
<thead>
<tr>
- <th scope="col" class="is-sorted">
+ <th scope="col" class="is-sorted" aria-sort="descending">
Listing
{% icon "ArrowDownSm" %}
</th> Screen readers can announce the initial state of the sorting even if interactive sorting isn't enabled for the table. I've noticed that the styling doesn't quite match the previous appearance, especially noticeable in the font using the default I think it just needs some CSS tweaks to get it looking and behaving like before when the text was directly within the (It might need additional tweaking for things I haven't noticed are not identical to before) I'd love it if the headers had a focus shadow/outline like we see on other elements (right now it's default for button), but I have no idea how to get those showing up without being cropped by the boundaries of the Now that there's a test framework for Stacks, hopefully we can add in tests to verify no breaking changes here (e.g. test Great work on implementing this! 🥳 Let me know if there's anything I can help with re. testing or anything. |
The current method of triggering a sort in tables is not accessible. This is due to the fact that you are attaching an event listener to the
click
event on an element that naturally is not clickable; therefore, keyboard only users are not capable of interacting with the headers since focus is never moved onto them.My proposed syntax moves the contents of a table header cell into a button, which is where the
data-action
attribute will now live.CSS Changes
I have added some rules described as follows:
.s-table__sortable thead th[data-s-table-target="column"]
:: if ath
has this attribute attached to it, then it should be assumed that it's a sortable column and the padding will come from the<button>
instead of it so that there's no weird gap between the button and the header cell that's not clickable.s-table__sortable thead th button
:: there are certain rules that need to happen here so I've stuffed them here to avoid repetition in our markupBackward Compatibility
I have introduced a
ensureHeadersAreClickable
method that transforms the old table syntax to the next syntax so that any Stacks table gets these a11y fixes for free! I currently have a warning in there telling devs in a non-prod environment to update their markup.What do these changes NOT do?
This PR does not change/improve any screen reader announcements in terms of announcing new sorting or changing of table captions. For the moment, we'll continue to rely on an SR's support of
aria-sort
.Resources