Skip to content

Refactor language picker as accordion#674

Merged
aduth merged 4 commits intomainfrom
aduth-language-picker-dropdown
Jul 12, 2021
Merged

Refactor language picker as accordion#674
aduth merged 4 commits intomainfrom
aduth-language-picker-dropdown

Conversation

@aduth
Copy link
Contributor

@aduth aduth commented Jul 9, 2021

Why:

  • Semantically, it's essentially the same thing. USWDS header dropdown navigation is also implemented as an accordion.
  • Avoids needing to maintain our own component implementation. Instead, we can leverage the battle-tested USWDS solution.
  • Because we no longer implement our own solution, we can now eliminate jQuery as a dependency (reduce size of main.js by 90%, from 98.8kb to 10.8kb)
  • Better isolation of styles allows for some portability if we want to bring this into the design system.
  • Fixes an accessibility issue where the globe image was previously announced as "image" without any text alternative (SC 1.1.1, "In order for elements with a role of img be perceivable, authors MUST provide alternative text or a label determined by the accessible name calculation."). Curious that neither Google Lighthouse nor aXe catches this 🤔 aXe browser extension does catch this on the live site.

Visually, the element should appear mostly the same, but is not identical. Revisions should only move in the direction of being more faithful to the original design.

  Before After
Desktop Navigation image image
Desktop Navigation (Open) image image
Mobile Navigation image image

aduth added 2 commits July 8, 2021 15:56
**Why**:

- Semantically, it's essentially the same thing.
- Avoids needing to maintain our own component implementation. Instead, we can leverage the battle-tested USWDS solution.
- Because we no longer implement our own solution, we can now eliminate jQuery as a dependency.
- Better isolation of styles allows for some portability if we want to bring this into the design system.
Copy link
Contributor

@zachmargolis zachmargolis left a comment

Choose a reason for hiding this comment

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

LGTM

@@ -1,26 +1,4 @@
import $ from 'jquery';
Copy link
Contributor

Choose a reason for hiding this comment

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

🔥 🔥 🔥

Comment on lines +27 to +46
{% if page.lang == 'en' %}
{% if locale == 'en' %}
{% assign locale_url = page.url %}
{% elsif locale == page.lang %}
{% assign locale_url = page.url %}
{% else %}
{% assign locale_url = page.url | prepend: locale | prepend: '/' %}
{% endif %}
{% else %}
{% if locale == 'en' and page.lang == 'es' %}
{% assign locale_url = page.url | remove_first: 'es/' %}
{% elsif locale == 'en' and page.lang == 'fr' %}
{% assign locale_url = page.url | remove_first: 'fr/' %}
{% elsif locale == page.lang %}
{% assign locale_url = page.url %}
{% else %}
{% assign locale_url = page.url | replace_first: page.lang, locale %}
{% endif %}
{% endif %}
<a href="{{ locale_url | prepend: site.baseurl }}" lang="{{ locale }}">
Copy link
Contributor

Choose a reason for hiding this comment

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

I see this is old/unchanged, but it's making my brain melt, I feel like we could probably turn this into a custom plugin in ruby and simplify what it's doing (whatever that is....)

(Not for this PR necessarily)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Need to do more testing, but I think we might be able to replace this with a one-liner:

Suggested change
{% if page.lang == 'en' %}
{% if locale == 'en' %}
{% assign locale_url = page.url %}
{% elsif locale == page.lang %}
{% assign locale_url = page.url %}
{% else %}
{% assign locale_url = page.url | prepend: locale | prepend: '/' %}
{% endif %}
{% else %}
{% if locale == 'en' and page.lang == 'es' %}
{% assign locale_url = page.url | remove_first: 'es/' %}
{% elsif locale == 'en' and page.lang == 'fr' %}
{% assign locale_url = page.url | remove_first: 'fr/' %}
{% elsif locale == page.lang %}
{% assign locale_url = page.url %}
{% else %}
{% assign locale_url = page.url | replace_first: page.lang, locale %}
{% endif %}
{% endif %}
<a href="{{ locale_url | prepend: site.baseurl }}" lang="{{ locale }}">
<a
href="{{ page.url | remove_first: 'es/' | remove_first: 'fr/' | prepend: locale | remove_first: 'en/' | prepend: '/' | prepend: site.baseurl }}"
lang="{{ locale }}"
>

Copy link
Contributor

Choose a reason for hiding this comment

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

omg winner

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think I misunderstood how remove_first works, so this might not work exactly as we want all the time, particularly when the path includes en/, fr/, es/ somewhere other than the start of the URL.

To your original suggestion, I think we could probably adapt our existing locale filters to support what we need here. I might do it separately.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Follow-up, for posterity: #676

@aduth
Copy link
Contributor Author

aduth commented Jul 9, 2021

I think I figured out why it wasn't being caught. The default viewport size for a Puppeteer page is quite small (800x600), and at that size the language dropdown isn't visible. We could increase the size, but then we might not catch issues which would only happen at smaller viewports 🤷

@zachmargolis
Copy link
Contributor

I think I figured out why it wasn't being caught. The default viewport size for a Puppeteer page is quite small (800x600), and at that size the language dropdown isn't visible. We could increase the size, but then we might not catch issues which would only happen at smaller viewports 🤷

the puppeteer specs for accessibility are fairly fast, would it make sense to run them at two sizes?

.usa-nav applies specific styles for links. Enforce a consistent padding and line-height on the language list items, and consistency to the language picker button via identical styling (padding, typeset).
aduth added a commit that referenced this pull request Jul 12, 2021
Context: #674 (comment)

**Why**: Due to media query styling, some issues are only present at one or the other viewport. Previously, the viewport was quite small so desktop-specific issues were not surfaced.
@aduth
Copy link
Contributor Author

aduth commented Jul 12, 2021

I think I figured out why it wasn't being caught. The default viewport size for a Puppeteer page is quite small (800x600), and at that size the language dropdown isn't visible. We could increase the size, but then we might not catch issues which would only happen at smaller viewports 🤷

the puppeteer specs for accessibility are fairly fast, would it make sense to run them at two sizes?

Yeah, I don't think it'd be much of an issue, and could help up discover similar issues like this one. I opened a separate pull request at #677, which should confirm (via failure) the issue being resolved here.

@aduth aduth merged commit 25d5b44 into main Jul 12, 2021
@aduth aduth deleted the aduth-language-picker-dropdown branch July 12, 2021 17:45
aduth added a commit that referenced this pull request Jul 12, 2021
Context: #674 (comment)

**Why**: Due to media query styling, some issues are only present at one or the other viewport. Previously, the viewport was quite small so desktop-specific issues were not surfaced.
aduth added a commit that referenced this pull request Jul 13, 2021
Context: #674 (comment)

**Why**: Due to media query styling, some issues are only present at one or the other viewport. Previously, the viewport was quite small so desktop-specific issues were not surfaced.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants