-
Notifications
You must be signed in to change notification settings - Fork 211
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 accessibility labels for filters tab and button #4396
Merged
Merged
Changes from 4 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
3265d2a
Add aria-label to VFilterTab
AetherUnbound 972ba83
Update filter's aria-label within translations
AetherUnbound bbedbed
Simplify VFilterTab by using $tc filter
AetherUnbound 6ac04e0
Fix tests
AetherUnbound 41770f3
Use a more stable locator for testing
AetherUnbound 32a834c
Use the plural translation for all cases
AetherUnbound bd4caeb
Update frontend/test/locales/ar.json
obulat 647ec29
Add a translator's note to the base translation file
AetherUnbound File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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.
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.
Generally it's best practice to avoid element id-based locators in tests. They don't mirror human behaviour at all, regardless of what or whether assistive technologies are in use. What's changed about the implementation that prevents selecting on the role and name any more? Is it because of the dynamic filter count? If so, we should use a regex to select based on a substring... you'll just need to copy in the RTL regex as distinct from the LTR (
/filters/
for LTR,/التصفية/
for RTL, these regexes appear to work for me locally in Node) and select which to use based on thedir
argument.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.
Our i18n setup in Playwright tests is quite basic, and does not have support for
$tc
.We do not want to use a hard-coded regex for the selector because the string might change without the changes to the key.
If we continue using the current test
t
function for this locator, it would returnFilter ({count})|Filters ({count})"
for English name of the tab. We could use some string manipulation and remove the part after the first(
, but then the usefulness of this kind of selector is very questionable. Besides, for RTL, the order of words might be different, and we could be removing the part of the string that is actually useful (if the parentheses are in the beginning of the phrase).My justification for this change was that this is a helper function used for opening the content settings modal. We could make sure that we use the role- and name- based selectors in the tests that specifically test the filters button and the way it opens the modal, and keep the
id
-based selector for the helper function used in other tests where this is not the behavior under test.That said, I wonder if we really need the pluralization in the filters tab label ("Filter (1)"/"Filters (n)" distinction). Always using "Filters" would simplify the code, but would it look correct for an English speaker? "Filters (1)" and "Filters (5)"?
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.
If we decide not to use pluralization for Filters, then this PR is ready. Otherwise, we will also need to update the
frontend/test/locales/ar.json
file with test values for Arabic (Google suggests "({count}) مرشح|مرشحات ({count})"), which will also probably cause the need to update RTL snapshotsThere 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.
There are a few things here:
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.
This would require a hard-coded regex instead of using the i18n keys.
I feel like there are 2 best practices that are in conflict here:
t
function instead of hard-coding strings.If we use the i18n key, we cannot easily create a regex that would correctly match the tab's accessible name because it would return
Filter ({count})|Filters ({count})"
, and we need to match"Filter (1)"
or"Filters (\d)"
. Even if we split the return value by a space, it would work for English("Filter" would match any variant), but I'm not sure it would work for Arabic (because the singular form might be very different from the plural one).If we use the hard-coded regex, then we are going back on "not using hard-coded strings in tests".
Is there something I'm not seeing?
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.
No, I don't think you're missing anything. You're right, on the face of it using a regex is in conflict with avoiding hard coded text. But when avoiding hard coded text (which is a preference to make changing tests easier) conflicts with a best practice focused on ensuring the application is accessible, I have to think the accessibility preference is more important. Neither of these are absolute best practices or preferences, but certainly the one intended to ensure the accessibility of the application should be considered more important than one meant to make the development experience of test writing slightly simpler.