Skip to content

Commit 409bef3

Browse files
committed
fix: only allow one top level nav item to be open at a time while rendering as a dropdown menu
1 parent d0155b5 commit 409bef3

File tree

1 file changed

+16
-1
lines changed
  • packages/uikit-workshop/src/scripts/components/pl-nav

1 file changed

+16
-1
lines changed

packages/uikit-workshop/src/scripts/components/pl-nav/pl-nav.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,22 @@ class Nav extends BaseComponent {
219219

220220
toggleNavPanel(e) {
221221
const target = e.target;
222-
target.classList.toggle('pl-is-active');
222+
223+
// when the Nav renders as a dropdown menu, only allow one menu to be open at a time to prevent overlap
224+
if (this.layoutMode !== 'vertical' && window.innerWidth > 670) {
225+
target.classList.toggle('pl-is-active');
226+
227+
this.topLevelTriggers = document.querySelectorAll(
228+
'.pl-c-nav__link--title.pl-is-active'
229+
);
230+
231+
this.topLevelTriggers.forEach(trigger => {
232+
if (trigger !== target) {
233+
trigger.classList.remove('pl-is-active');
234+
trigger.nextSibling.classList.remove('pl-is-active');
235+
}
236+
});
237+
}
223238
}
224239

225240
rendered() {

0 commit comments

Comments
 (0)