Skip to content
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 8 commits into from
May 30, 2024

Conversation

AetherUnbound
Copy link
Collaborator

@AetherUnbound AetherUnbound commented May 28, 2024

Fixes

Fixes #957 by @obulat

Description

This PR adds a common aria-label to both the VFilterTab and VFilterButton (based on feedback provided in #957) which more appropriately conveys in text format what sighted users are expected to understand about the action component. The new label takes the form (in English) of Filters ({number}).

I've opted to reduce the set of changes to just this, since the testing translation changes were pretty unrelated and this makes the changeset much smaller.

Testing Instructions

  1. Run the app locally using just frontend/run dev
  2. Visit http://localhost:8443/search/?q=cats&license=pdm,cc0,by using a wide viewport
  3. Right click on the filters button, and click "Inspect Accessibility Properties" (for firefox, not sure what this looks like in Chrome)
  4. Verify that the text present for the button is Filters (3)
  5. Change to a smaller viewport for mobile devices and reload the page
  6. Open up the filters drawer with the button next to search
  7. Right click on the filter tab and click "Inspect Accessibility Properties"
  8. Verify that the text present for the button is Filters (3)

Checklist

  • My pull request has a descriptive title (not a vague title likeUpdate index.md).
  • My pull request targets the default branch of the repository (main) or a parent feature branch.
  • My commit messages follow best practices.
  • My code follows the established code style of the repository.
  • I added or updated tests for the changes I made (if applicable).
  • I added or updated documentation (if applicable).
  • I tried running the project locally and verified that there are no visible errors.
  • I ran the DAG documentation generator (just catalog/generate-docs for catalog
    PRs) or the media properties generator (just catalog/generate-docs media-props
    for the catalog or just api/generate-docs for the API) where applicable.

Developer Certificate of Origin

Developer Certificate of Origin
Developer Certificate of Origin
Version 1.1

Copyright (C) 2004, 2006 The Linux Foundation and its contributors.
1 Letterman Drive
Suite D4700
San Francisco, CA, 94129

Everyone is permitted to copy and distribute verbatim copies of this
license document, but changing it is not allowed.


Developer's Certificate of Origin 1.1

By making a contribution to this project, I certify that:

(a) The contribution was created in whole or in part by me and I
    have the right to submit it under the open source license
    indicated in the file; or

(b) The contribution is based upon previous work that, to the best
    of my knowledge, is covered under an appropriate open source
    license and I have the right under that license to submit that
    work with modifications, whether created in whole or in part
    by me, under the same open source license (unless I am
    permitted to submit under a different license), as indicated
    in the file; or

(c) The contribution was provided directly to me by some other
    person who certified (a), (b) or (c) and I have not modified
    it.

(d) I understand and agree that this project and the contribution
    are public and that a record of the contribution (including all
    personal information I submit with it, including my sign-off) is
    maintained indefinitely and may be redistributed consistent with
    this project or the open source license(s) involved.

@AetherUnbound AetherUnbound requested review from a team as code owners May 28, 2024 00:37
@openverse-bot openverse-bot added 🟨 priority: medium Not blocking but should be addressed soon ✨ goal: improvement Improvement to an existing user-facing feature ♿️ aspect: a11y Concerns related to the project's accessibility 🚦 status: awaiting triage Has not been triaged & therefore, not ready for work labels May 28, 2024
@github-actions github-actions bot added 🧱 stack: frontend Related to the Nuxt frontend 🧱 stack: mgmt Related to repo management and automations labels May 28, 2024
@AetherUnbound AetherUnbound removed the 🚦 status: awaiting triage Has not been triaged & therefore, not ready for work label May 28, 2024
Copy link
Collaborator

@sarayourfriend sarayourfriend left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Only blocker is to not change the translation key (set it back to filterButton), but otherwise this works great 😁

frontend/src/locales/scripts/en.json5 Outdated Show resolved Hide resolved
@sarayourfriend
Copy link
Collaborator

do we need to follow the steps of the upload portion of the i18n documentation before/after this PR is merged?

Nope, it's handled automatically in this GitHub workflow when merging to main: https://github.com/WordPress/openverse/actions/workflows/generate_pot.yml

After merging, no need for any further intervention.

Copy link
Contributor

@obulat obulat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I looked at the visual regression test failures, but didn't understand what the problem is yet. As for the e2e tests, this patch should fix some of them:

Subject: [PATCH] Add catalog media properties docs

Signed-off-by: Olga Bulat <[email protected]>
---
Index: frontend/test/playwright/utils/navigation.ts
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/frontend/test/playwright/utils/navigation.ts b/frontend/test/playwright/utils/navigation.ts
--- a/frontend/test/playwright/utils/navigation.ts	(revision d5123efe3d891dad612c8581d1fd36f166b0d9a5)
+++ b/frontend/test/playwright/utils/navigation.ts	(date 1716920676271)
@@ -50,11 +50,10 @@
 export const openContentSettingsTab = async (
   page: Page,
   tab: "searchTypes" | "filters" = "searchTypes",
-  dir: LanguageDirection = "ltr"
 ) => {
-  const tabKey = tab === "searchTypes" ? "searchType.heading" : "filters.title"
+  const tabId = tab === "searchTypes" ? "content-settings" : "filters"
 
-  await page.getByRole("tab", { name: t(tabKey, dir) }).click()
+  await page.locator(`#tab-${tabId}`).click()
 }
 
 /**
@@ -105,7 +104,7 @@
       await buttonLocator.isEnabled()
       await buttonLocator.click()
     }
-    return openContentSettingsTab(page, contentSwitcherKind, dir)
+    return openContentSettingsTab(page, contentSwitcherKind)
   } else if (isPressed) {
     await closeContentSettingsModal(page, dir)
   }

Copy link
Collaborator

@sarayourfriend sarayourfriend left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This LGTM. I've left one comment regarding the use of an element-id selector in the test, which goes against best practices. I'm comfortable with you fixing it in a fast-follow PR to this one rather than blocking this PR now, but it does need to be fixed.

Comment on lines 57 to 56
await page.getByRole("tab", { name: t(tabKey, dir) }).click()
await page.locator(`#tab-${tabId}`).click()
Copy link
Collaborator

@sarayourfriend sarayourfriend May 29, 2024

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 the dir argument.

Copy link
Contributor

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 return Filter ({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)"?

Copy link
Contributor

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 snapshots

Copy link
Collaborator

@sarayourfriend sarayourfriend May 29, 2024

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:

  1. My understanding is that pluralization might not be necessary because it's a stable name of the tab, not a reference to the number of filters applied. It's " Filters ({count} )", in a sense? I don't know if that comes across in all languages, or even to the translator, and regardless of what we pick, we should put a translator note to explain the context for this string.
  2. Whether we pluralise or not is irrelevant to the question of a regex. The regex intentionally doesn't match the entire string and only the part that would be stable (and pulled from our stable testing environment documents, which are predictable). We don't need to update the testing translations to literally reflect the actual translation. The testing translations need to be plausible, and ideally somewhat reflect the length of the string in the tested language. So long as this tab is the filters tab, the search string would never change.
  3. Navigation utilities, perhaps most of all, should follow the best practices for navigating the app "using the tools a human would have" because they're implicitly testing that getting around the application works for a human (as close as we can get). End-to-end tests are not unit tests, they are integration tests. I don't think they should take artificial short-cuts.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2. Whether we pluralise or not is irrelevant to the question of a regex. The regex intentionally doesn't match the entire string and only the part that would be stable (and pulled from our stable testing environment documents, which are predictable). We don't need to update the testing translations to literally reflect the actual translation. The testing translations need to be plausible, and ideally somewhat reflect the length of the string in the tested language. So long as this tab is the filters tab, the search string would never change.

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:

  • use role and name based selectors to mirror the user behavior
  • use the i18n keys and 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?

Copy link
Collaborator

@sarayourfriend sarayourfriend May 29, 2024

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.

Copy link
Contributor

@obulat obulat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I realized that we don't use a pluralized (i.e., 1 filter/2 filters) for the visible label, it's always "Filters". So, we could probably use the single "Filters ({count})" for the aria-label as well.

In light of the discussion with @sarayourfriend, I created a patch that reverts the locator changes, and updates the filter locator to fix the tests:

Subject: [PATCH] Test fixes
---
Index: frontend/test/playwright/utils/navigation.ts
<+>UTF-8
===================================================================
diff --git a/frontend/test/playwright/utils/navigation.ts b/frontend/test/playwright/utils/navigation.ts
--- a/frontend/test/playwright/utils/navigation.ts
+++ b/frontend/test/playwright/utils/navigation.ts
@@ -49,11 +49,13 @@
  */
 export const openContentSettingsTab = async (
   page: Page,
-  tab: "searchTypes" | "filters" = "searchTypes"
+  tab: "searchTypes" | "filters" = "searchTypes",
+  dir: LanguageDirection = "ltr"
 ) => {
-  const tabId = tab === "searchTypes" ? "content-settings" : "filters"
+  // Use a hard-coded Regex to match the dynamic Filters tab name
+  const tabName = tab === "searchTypes" ? t("searchType.heading", dir) : dir === "ltr" ? /filter/i : /مرش/
 
-  await page.locator(`#tab-${tabId}`).click()
+  await page.getByRole("tab", { name: tabName }).click()
 }
 
 /**
@@ -104,7 +106,7 @@
       await buttonLocator.isEnabled()
       await buttonLocator.click()
     }
-    return openContentSettingsTab(page, contentSwitcherKind)
+    return openContentSettingsTab(page, contentSwitcherKind, dir)
   } else if (isPressed) {
     await closeContentSettingsModal(page, dir)
   }
Index: frontend/test/locales/ar.json
<+>UTF-8
===================================================================
diff --git a/frontend/test/locales/ar.json b/frontend/test/locales/ar.json
--- a/frontend/test/locales/ar.json
+++ b/frontend/test/locales/ar.json
@@ -52,7 +52,7 @@
     "loading": "جار التحميل...",
     "filterButton": {
       "simple": "مرشحات",
-      "withCount": "{count} عامل التصفية | {count} عوامل التصفية"
+      "withCount": "({count}) مرشحات|({count}) مرشح"
     },
     "seeResults": "انظر النتائج",
     "backButton": "عُد",

@AetherUnbound
Copy link
Collaborator Author

Thank you @obulat for the patch! I've applied it and simplified the English translation. Let me know if anything else is needed for this!

Copy link
Collaborator

@sarayourfriend sarayourfriend left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Just a tip for adding a translators note and maybe a question to follow up with the GlotPress folks to make sure we're doing the best thing for them, but I don't think it needs to block this PR.

frontend/src/locales/scripts/en.json5 Show resolved Hide resolved
Copy link
Contributor

@obulat obulat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated the Arabic text to also only include the plural version.
Congratulations on your big frontend PR ✨

@AetherUnbound AetherUnbound merged commit 848f2ab into main May 30, 2024
43 checks passed
@AetherUnbound AetherUnbound deleted the fix/filter-a11y-label branch May 30, 2024 16:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
♿️ aspect: a11y Concerns related to the project's accessibility ✨ goal: improvement Improvement to an existing user-facing feature 🟨 priority: medium Not blocking but should be addressed soon 🧱 stack: frontend Related to the Nuxt frontend 🧱 stack: mgmt Related to repo management and automations
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Better accessible name for Filters button and tab
4 participants