generated from adobe/aem-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 191
Implement Arrow keyboard navigation for mobile gnav components #4218
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
abe4409
Implement Arrow keyboard navigation for mobile gnav components
patel-prince fe0b6c4
add navigation logic for promo links
patel-prince a2f2ab9
remove consoles
patel-prince 0f24039
Merge branch 'stage' of https://github.com/adobecom/milo into MWPW-17…
patel-prince 6838689
Merge branch 'stage' of https://github.com/adobecom/milo into MWPW-17…
patel-prince 6b54393
keep focus on close button when menu open
patel-prince 4c70b62
add some review changes
patel-prince 1e63b6c
use optional chaining as suggested in review
patel-prince 635e7a8
Merge branch 'stage' of https://github.com/adobecom/milo into MWPW-17…
patel-prince f722fd0
review changes and updates
patel-prince 8a6a261
Merge branch 'stage' of https://github.com/adobecom/milo into MWPW-17…
patel-prince 9b24a3f
refactoring to switch case as suggested in review changes
patel-prince 0d3a7a9
Merge branch 'stage' of https://github.com/adobecom/milo into MWPW-17…
patel-prince c2e3aba
Merge branch 'stage' of https://github.com/adobecom/milo into MWPW-17…
patel-prince 3ea9a4e
Merge branch 'stage' of https://github.com/adobecom/milo into MWPW-17…
patel-prince 00f3888
optimize as per the review changes
patel-prince 5e4b137
use optional chaining
patel-prince c802d94
Shift-tab focus does not function for breadcrumbs on Tablet Mobile de…
patel-prince c61b875
Merge branch 'stage' of https://github.com/adobecom/milo into MWPW-17…
patel-prince e9005da
Merge branch 'stage' of https://github.com/adobecom/milo into MWPW-17…
patel-prince 099011d
Merge branch 'stage' of https://github.com/adobecom/milo into MWPW-17…
patel-prince 71701bf
fix focus fedsnavlinks when sybheader level 3 is present
patel-prince 63fd7d2
focus selected tab on submenu open if focus mode is on
patel-prince 122a1ac
add rtl support
patel-prince 3a33aef
Merge branch 'stage' of https://github.com/adobecom/milo into MWPW-17…
patel-prince File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
126 changes: 126 additions & 0 deletions
126
libs/blocks/global-navigation/utilities/keyboard/mobileGnav.js
This file contains hidden or 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,126 @@ | ||
import { isDesktop } from '../utilities.js'; | ||
|
||
const MobileGnav = { | ||
init() { | ||
this.isMobile = !isDesktop.matches; | ||
this.toggleButton = document.querySelector('.feds-toggle'); | ||
this.menuItemLinks = document.querySelectorAll('.feds-nav-wrapper section.feds-navItem > .feds-navLink'); | ||
this.eventInitialized = false; | ||
this.addEventListeners(); | ||
}, | ||
addEventListeners() { | ||
this.toggleButton.addEventListener('keydown', ({ code }) => { | ||
if (!this.isMobile) return; | ||
const gnavWrapper = document.querySelector('.feds-nav-wrapper'); | ||
if (code === 'ArrowDown' && gnavWrapper?.classList.contains('feds-nav-wrapper--expanded')) { | ||
const firstNavLink = gnavWrapper.querySelector('.feds-nav .feds-navLink'); | ||
firstNavLink.focus(); | ||
} | ||
}); | ||
this.toggleButton.addEventListener('click', () => { | ||
if (!this.isMobile) return; | ||
const gnavWrapper = document.querySelector('.feds-nav-wrapper'); | ||
if (gnavWrapper?.classList.contains('feds-nav-wrapper--expanded')) { | ||
if (!this.eventInitialized) { | ||
this.eventInitialized = true; | ||
const popupTabs = document.querySelectorAll('.feds-nav-wrapper .feds-popup .tabs .tab'); | ||
const popupTabContents = document.querySelectorAll('.feds-nav-wrapper .feds-popup .tab-content'); | ||
const popupLinks = document.querySelectorAll('.feds-nav-wrapper .feds-popup .tab-content a.feds-navLink, .feds-promo a'); | ||
popupTabs.forEach((tab) => { | ||
tab.addEventListener('keydown', ({ code }) => { | ||
switch (code) { | ||
case 'ArrowUp': { | ||
const prevTab = tab.previousElementSibling; | ||
if (prevTab) prevTab.focus(); | ||
break; | ||
} | ||
case 'ArrowDown': { | ||
const nextTab = tab.nextElementSibling; | ||
if (nextTab) nextTab.focus(); | ||
break; | ||
} | ||
case (document.dir !== 'rtl' ? 'ArrowRight' : 'ArrowLeft'): { | ||
const currentTabs = [...popupTabs].filter((currentTab) => currentTab.closest('.feds-dropdown--active')); | ||
const activeTab = currentTabs.find((currentTab) => currentTab.getAttribute('aria-selected') === 'true'); | ||
const activeTabIndex = activeTab.getAttribute('aria-controls'); | ||
const currentTabContent = [...popupTabContents].find((currentTab) => currentTab.closest('.feds-dropdown--active')); | ||
if (currentTabContent && currentTabContent.children[activeTabIndex]) { | ||
currentTabContent.children[activeTabIndex].querySelector('a.feds-navLink, .feds-promo a').focus(); | ||
} | ||
break; | ||
} | ||
default: | ||
break; | ||
} | ||
}); | ||
}); | ||
popupLinks.forEach((link) => { | ||
link.addEventListener('keydown', ({ code }) => { | ||
switch (code) { | ||
case 'ArrowUp': { | ||
let prevLink = link.previousElementSibling; | ||
if (prevLink?.classList.contains('feds-promo-wrapper')) { | ||
prevLink = prevLink.querySelector('a.feds-cta'); | ||
} | ||
if (prevLink?.tagName === 'DIV' && prevLink.classList.contains('feds-navLink')) { | ||
prevLink = prevLink.previousElementSibling; | ||
} | ||
if (prevLink) { | ||
prevLink.focus(); | ||
} else if (link.classList.contains('feds-cta')) { | ||
link.closest('.feds-promo-content').previousElementSibling.focus(); | ||
} else { | ||
link.closest('.feds-promo-wrapper').previousElementSibling.focus(); | ||
} | ||
break; | ||
} | ||
case 'ArrowDown': { | ||
let nextLink = link.nextElementSibling; | ||
if (nextLink?.classList.contains('feds-promo-content')) { | ||
nextLink = nextLink.querySelector('a'); | ||
} | ||
if (nextLink?.classList.contains('feds-promo-wrapper')) { | ||
nextLink = nextLink.querySelector('a'); | ||
} | ||
if (nextLink?.tagName === 'DIV' && nextLink.classList.contains('feds-navLink')) { | ||
nextLink = nextLink.nextElementSibling; | ||
} | ||
if (nextLink) { | ||
nextLink.focus(); | ||
} else { | ||
link.closest('.feds-promo-wrapper').nextElementSibling.focus(); | ||
} | ||
break; | ||
} | ||
case (document.dir === 'rtl' ? 'ArrowRight' : 'ArrowLeft'): { | ||
const currentTabs = [...popupTabs].filter((currentTab) => currentTab.closest('.feds-dropdown--active')); | ||
const activeTab = currentTabs.find((currentTab) => currentTab.getAttribute('aria-selected') === 'true'); | ||
if (activeTab) activeTab.focus(); | ||
break; | ||
} | ||
default: | ||
break; | ||
} | ||
}); | ||
}); | ||
} | ||
} | ||
}); | ||
|
||
this.menuItemLinks.forEach((menulink, index) => { | ||
menulink.addEventListener('keydown', ({ code }) => { | ||
if (!this.isMobile) return; | ||
if (code === 'ArrowUp') { | ||
const prevLink = this.menuItemLinks[index - 1]; | ||
if (prevLink) prevLink.focus(); | ||
else this.toggleButton.focus(); | ||
} else if (code === 'ArrowDown') { | ||
const nextLink = this.menuItemLinks[index + 1]; | ||
if (nextLink) nextLink.focus(); | ||
} | ||
}); | ||
}); | ||
}, | ||
}; | ||
|
||
export default MobileGnav; |
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.