generated from adobe/aem-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 175
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[MWPW-163735] - Added Local Nav keyboard navigation for mobile GNAV r…
…edesign (#3321) * Added localnav keyboard navigation for mobile gnav redesign * Added fixes for Local nav along with keyboard navigation * lint fix
- Loading branch information
Showing
7 changed files
with
158 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
libs/blocks/global-navigation/utilities/keyboard/localNav.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { selectors } from './utils.js'; | ||
import { trigger, setActiveDropdown } from '../utilities.js'; | ||
|
||
class LocalNavItem { | ||
constructor() { | ||
this.localNav = document.querySelector(selectors.localNav); | ||
this.localNavTrigger = this.localNav?.querySelector(selectors.localNavTitle); | ||
this.exitLink = this.localNav?.querySelector(selectors.localNavExit); | ||
this.addEventListeners(); | ||
} | ||
|
||
static handleKeyDown = (e) => { | ||
const isHeadline = e.target.classList.contains(selectors.headline.slice(1)); | ||
switch (e.code) { | ||
case 'Space': | ||
case 'Enter': | ||
if (isHeadline) { | ||
e.preventDefault(); // Prevent default scrolling behavior for Space key | ||
trigger({ element: e.target, event: e, type: 'headline' }); | ||
setActiveDropdown(e.target); | ||
} | ||
break; | ||
default: | ||
break; | ||
} | ||
}; | ||
|
||
addEventListeners = () => { | ||
this.localNav?.addEventListener('keydown', LocalNavItem.handleKeyDown); | ||
this.exitLink?.addEventListener('focus', (e) => { | ||
e.preventDefault(); | ||
this.localNavTrigger?.click(); | ||
this.localNavTrigger?.focus(); | ||
}); | ||
}; | ||
} | ||
|
||
export default LocalNavItem; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters