Skip to content

Commit

Permalink
[Header drawer] fix header locales closing dropdown too soon and ESC …
Browse files Browse the repository at this point in the history
…behaviour (#2472)
  • Loading branch information
ludoboludo authored Apr 6, 2023
1 parent 2ff714f commit 93078bf
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
4 changes: 3 additions & 1 deletion assets/global.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ document.querySelectorAll('[id^="Details-"] summary').forEach((summary) => {
event.currentTarget.setAttribute('aria-expanded', !event.currentTarget.closest('details').hasAttribute('open'));
});

if (summary.closest('header-drawer')) return;
if (summary.closest('header-drawer, menu-drawer')) return;
summary.parentElement.addEventListener('keyup', onKeyUpEscape);
});

Expand Down Expand Up @@ -418,6 +418,8 @@ class MenuDrawer extends HTMLElement {
document.body.classList.remove(`overflow-hidden-${this.dataset.breakpoint}`);
removeTrapFocus(elementToFocus);
this.closeAnimation(this.mainDetailsToggle);

if (event instanceof KeyboardEvent) elementToFocus?.setAttribute('aria-expanded', false);
}

onFocusOut() {
Expand Down
2 changes: 2 additions & 0 deletions assets/localization-form.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ if (!customElements.get('localization-form')) {
onContainerKeyUp(event) {
if (event.code.toUpperCase() !== 'ESCAPE') return;

if(this.elements.button.getAttribute('aria-expanded') == 'false') return;
this.hidePanel();
event.stopPropagation();
this.elements.button.focus();
}

Expand Down
2 changes: 1 addition & 1 deletion snippets/header-drawer.liquid
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
{% render 'icon-close' %}
</span>
</summary>
<div id="menu-drawer" class="gradient menu-drawer motion-reduce" tabindex="-1">
<div id="menu-drawer" class="gradient menu-drawer motion-reduce">
<div class="menu-drawer__inner-container">
<div class="menu-drawer__navigation-container">
<nav class="menu-drawer__navigation">
Expand Down

0 comments on commit 93078bf

Please sign in to comment.