Skip to content

Commit

Permalink
fix(left-nav): resetting items expanded after close hamb. menu (carbo…
Browse files Browse the repository at this point in the history
…n-design-system#4956)

### Related Ticket(s)

Web components: Masthead with L1 - Hamburger menu not getting reset, on closing from sub-menu options. carbon-design-system#4592

### Description

Resetting items expanded after close hamb. menu
  • Loading branch information
guilhermelMoraes authored and IgnacioBecerra committed Feb 22, 2021
1 parent 98b9084 commit 90debf7
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions packages/web-components/src/components/masthead/left-nav.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* @license
*
* Copyright IBM Corp. 2020
* Copyright IBM Corp. 2020, 2021
*
* This source code is licensed under the Apache-2.0 license found in the
* LICENSE file in the root directory of this source tree.
Expand All @@ -20,6 +20,7 @@ import Handle from '../../globals/internal/handle';
import StableSelectorMixin from '../../globals/mixins/stable-selector';
import DDSLeftNavOverlay from './left-nav-overlay';
import styles from './masthead.scss';
import DDSLeftNavMenu from './left-nav-menu';

const { prefix } = settings;
const { stablePrefix: ddsPrefix } = ddsSettings;
Expand Down Expand Up @@ -116,8 +117,16 @@ class DDSLeftNav extends StableSelectorMixin(BXSideNav) {
const { expanded, _startSentinelNode: startSentinelNode, _endSentinelNode: endSentinelNode } = this;
if (expanded) {
this._hFocusWrap = focuswrap(this.shadowRoot!, [startSentinelNode, endSentinelNode]);
} else if (this._hFocusWrap) {
this._hFocusWrap = this._hFocusWrap.release();
} else {
const { selectorNavItemsExpanded } = this.constructor as typeof DDSLeftNav;

this.querySelectorAll(selectorNavItemsExpanded).forEach(ddsLeftNavMenu => {
(ddsLeftNavMenu as DDSLeftNavMenu).expanded = false;
});

if (this._hFocusWrap) {
this._hFocusWrap = this._hFocusWrap.release();
}
}
}
}
Expand All @@ -144,6 +153,13 @@ class DDSLeftNav extends StableSelectorMixin(BXSideNav) {
return `${ddsPrefix}-left-nav-item,${ddsPrefix}-left-nav-menu,${ddsPrefix}-left-nav-menu-item`;
}

/**
* A selector that will return expanded nav menus.
*/
static get selectorNavItemsExpanded() {
return `${ddsPrefix}-left-nav-menu[expanded]`;
}

/**
* A selector selecting tabbable nodes.
*/
Expand Down

0 comments on commit 90debf7

Please sign in to comment.