Skip to content

Commit a18305a

Browse files
authored
fix(gcds-top-nav/gcds-side-nav): Issues with mobile menu closing (#1029)
1 parent 0a2a5f1 commit a18305a

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

packages/web/src/components/gcds-side-nav/gcds-side-nav.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ export class GcdsSideNav {
8585

8686
@Listen('focusout', { target: 'document' })
8787
async focusOutListener(e) {
88-
if (!this.el.contains(e.relatedTarget)) {
88+
if (e.relatedTarget !== null && e.relatedTarget !== this.el && !this.el.contains(e.relatedTarget)) {
8989
if (this.navSize == 'mobile') {
9090
if (this.mobile.hasAttribute('open')) {
9191
await this.mobile.toggleNav();
@@ -98,6 +98,9 @@ export class GcdsSideNav {
9898
async keyDownListener(e) {
9999
if (this.el.contains(document.activeElement)) {
100100
handleKeyDownNav(e, this.el, this.navItems);
101+
} if (this.navSize == 'mobile' && this.mobile.open == true && e.key == 'Escape') {
102+
// Close mobile nav on ESC
103+
await this.mobile.toggleNav();
101104
}
102105
}
103106

packages/web/src/components/gcds-top-nav/gcds-top-nav.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ export class GcdsTopNav {
102102

103103
@Listen('focusout', { target: 'document' })
104104
async focusOutListener(e) {
105-
if (!this.el.contains(e.relatedTarget)) {
105+
if (e.relatedTarget !== null && e.relatedTarget !== this.el && !this.el.contains(e.relatedTarget)) {
106106
if (this.navSize == 'mobile') {
107107
if (this.mobile.hasAttribute('open')) {
108108
await this.mobile.toggleNav();
@@ -115,6 +115,9 @@ export class GcdsTopNav {
115115
async keyDownListener(e) {
116116
if (this.el.contains(document.activeElement)) {
117117
handleKeyDownNav(e, this.el, this.navItems);
118+
} else if (this.navSize == 'mobile' && this.mobile.open == true && e.key == 'Escape') {
119+
// Close mobile nav on ESC
120+
await this.mobile.toggleNav();
118121
}
119122
}
120123

0 commit comments

Comments
 (0)