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

[Header] No-js behaviour for locale selectors #2485

Merged
merged 3 commits into from
Apr 7, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 38 additions & 4 deletions sections/header.liquid
Original file line number Diff line number Diff line change
Expand Up @@ -248,9 +248,26 @@
<div class="header__icons{% if section.settings.enable_country_selector or section.settings.enable_language_selector %} header__icons--localization header__localization{% endif %}">
<div class="desktop-localization-wrapper">
{%- if section.settings.enable_country_selector and localization.available_countries.size > 1 -%}
<localization-form class="small-hide medium-hide">
<noscript class="small-hide medium-hide">
{%- form 'localization', id: 'HeaderCountryMobileFormNoScript', class: 'localization-form' -%}
<div class="localization-form__select">
<h2 class="visually-hidden" id="HeaderCountryMobileLabelNoScript">{{ 'localization.country_label' | t }}</h2>
Copy link
Contributor

Choose a reason for hiding this comment

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

Why h2 and not a label?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Reusing the approach from the footer and also what's in the JS approach. I believe the reason why is because it helps navigate to it more easily when using a screen reader and using the VoiceOver rotor which shows you all the page's headings.

<select class="localization-selector link" name="country_code" aria-labelledby="HeaderCountryMobileLabelNoScript">
{%- for country in localization.available_countries -%}
<option value="{{ country.iso_code }}" {%- if country.iso_code == localization.country.iso_code %} selected{% endif %}>
{{ country.name }} ({{ country.currency.iso_code }} {{ country.currency.symbol }})
</option>
{%- endfor -%}
</select>
{% render 'icon-caret' %}
</div>
<button class="button button--tertiary">{{ 'localization.update_country' | t }}</button>
{%- endform -%}
</noscript>

<localization-form class="small-hide medium-hide no-js-hidden">
{%- form 'localization', id: 'HeaderCountryForm', class: 'localization-form' -%}
<div class="no-js-hidden">
Copy link
Contributor

Choose a reason for hiding this comment

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

Non blocking but just curious: do you know why no-js-hidden was on the inner div before?

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'm not sure tbh. If I left it the way it was, I'd get some unwanted space around the selectors. It's like that in the footer, so I think it was mostly copied over.
I can't really think of a reason why it wouldn't be on the parent 🤔

<div>
<h2 class="visually-hidden" id="HeaderCountryLabel">{{ 'localization.country_label' | t }}</h2>
{%- render 'country-localization', localPosition: 'HeaderCountry' -%}
</div>
Expand All @@ -259,9 +276,26 @@
{% endif %}

{%- if section.settings.enable_language_selector and localization.available_languages.size > 1 -%}
<localization-form class="small-hide medium-hide">
<noscript class="small-hide medium-hide">
{%- form 'localization', id: 'HeaderLanguageMobileFormNoScript', class: 'localization-form' -%}
<div class="localization-form__select">
<h2 class="visually-hidden" id="HeaderLanguageMobileLabelNoScript">{{ 'localization.language_label' | t }}</h2>
<select class="localization-selector link" name="locale_code" aria-labelledby="HeaderLanguageMobileLabelNoScript">
{%- for language in localization.available_languages -%}
<option value="{{ language.iso_code }}" lang="{{ language.iso_code }}" {%- if language.iso_code == localization.language.iso_code %} selected{% endif %}>
{{ language.endonym_name | capitalize }}
</option>
{%- endfor -%}
</select>
{% render 'icon-caret' %}
</div>
<button class="button button--tertiary">{{ 'localization.update_language' | t }}</button>
{%- endform -%}
</noscript>

<localization-form class="small-hide medium-hide no-js-hidden">
{%- form 'localization', id: 'HeaderLanguageForm', class: 'localization-form' -%}
<div class="no-js-hidden">
<div>
<h2 class="visually-hidden" id="HeaderLanguageLabel">{{ 'localization.language_label' | t }}</h2>
{%- render 'language-localization', localPosition: 'HeaderLanguage' -%}
</div>
Expand Down
69 changes: 65 additions & 4 deletions snippets/header-drawer.liquid
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,38 @@
{%- if section.settings.enable_country_selector or section.settings.enable_language_selector -%}
<div class="menu-drawer__localization header__localization">
{%- if section.settings.enable_country_selector and localization.available_countries.size > 1 -%}
<localization-form>
<noscript>
{%- form 'localization', id: 'HeaderCountryMobileFormNoScriptDrawer', class: 'localization-form' -%}
<div class="localization-form__select">
<h2 class="visually-hidden" id="HeaderCountryMobileLabelNoScriptDrawer">
{{ 'localization.country_label' | t }}
</h2>
<select
class="localization-selector link"
name="country_code"
aria-labelledby="HeaderCountryMobileLabelNoScriptDrawer"
>
{%- for country in localization.available_countries -%}
<option
value="{{ country.iso_code }}"
{%- if country.iso_code == localization.country.iso_code %}
selected
{% endif %}
>
{{ country.name }} ({{ country.currency.iso_code }}
{{ country.currency.symbol }})
</option>
{%- endfor -%}
</select>
{% render 'icon-caret' %}
</div>
<button class="button button--tertiary">{{ 'localization.update_country' | t }}</button>
{%- endform -%}
</noscript>

<localization-form class="no-js-hidden">
{%- form 'localization', id: 'HeaderCountryMobileForm', class: 'localization-form' -%}
<div class="no-js-hidden">
<div>
<h2 class="visually-hidden" id="HeaderCountryMobileLabel">
{{ 'localization.country_label' | t }}
</h2>
Expand All @@ -142,9 +171,41 @@
{% endif %}

{%- if section.settings.enable_language_selector and localization.available_languages.size > 1 -%}
<localization-form>
<noscript>
{%- form 'localization',
id: 'HeaderLanguageMobileFormNoScriptDrawer',
class: 'localization-form'
-%}
<div class="localization-form__select">
<h2 class="visually-hidden" id="HeaderLanguageMobileLabelNoScriptDrawer">
{{ 'localization.language_label' | t }}
</h2>
<select
class="localization-selector link"
name="locale_code"
aria-labelledby="HeaderLanguageMobileLabelNoScriptDrawer"
>
{%- for language in localization.available_languages -%}
<option
value="{{ language.iso_code }}"
lang="{{ language.iso_code }}"
{%- if language.iso_code == localization.language.iso_code %}
selected
{% endif %}
>
{{ language.endonym_name | capitalize }}
</option>
{%- endfor -%}
</select>
{% render 'icon-caret' %}
</div>
<button class="button button--tertiary">{{ 'localization.update_language' | t }}</button>
{%- endform -%}
</noscript>

<localization-form class="no-js-hidden">
{%- form 'localization', id: 'HeaderLanguageMobileForm', class: 'localization-form' -%}
<div class="no-js-hidden">
<div>
<h2 class="visually-hidden" id="HeaderLanguageMobileLabel">
{{ 'localization.language_label' | t }}
</h2>
Expand Down