8000 Implement Arrow keyboard navigation for mobile gnav components by patel-prince · Pull Request #4218 · adobecom/milo · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

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 25 commits into from
Jul 5, 2025
Merged
Show file tree
Hide file tree
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 May 21, 2025
fe0b6c4
add navigation logic for promo links
patel-prince May 21, 2025
a2f2ab9
remove consoles
patel-prince May 21, 2025
0f24039
Merge branch 'stage' of https://github.com/adobecom/milo into MWPW-17…
patel-prince May 22, 2025
6838689
Merge branch 'stage' of https://github.com/adobecom/milo into MWPW-17…
patel-prince May 26, 2025
6b54393
keep focus on close button when menu open
patel-prince May 26, 2025
4c70b62
add some review changes
patel-prince May 27, 2025
1e63b6c
use optional chaining as suggested in review
patel-prince May 27, 2025
635e7a8
Merge branch 'stage' of https://github.com/adobecom/milo into MWPW-17…
patel-prince Jun 3, 2025
f722fd0
review changes and updates
patel-prince Jun 10, 2025
8a6a261
Merge branch 'stage' of https://github.com/adobecom/milo into MWPW-17…
patel-prince Jun 10, 2025
9b24a3f
refactoring to switch case as suggested in review changes
patel-prince Jun 11, 2025
0d3a7a9
Merge branch 'stage' of https://github.com/adobecom/milo into MWPW-17…
patel-prince Jun 11, 2025
c2e3aba
Merge branch 'stage' of https://github.com/adobecom/milo into MWPW-17…
patel-prince Jun 13, 2025
3ea9a4e
Merge branch 'stage' of https://github.com/adobecom/milo into MWPW-17…
patel-prince Jun 16, 2025
00f3888
optimize as per the review changes
patel-prince Jun 16, 2025
5e4b137
use optional chaining
patel-prince Jun 16, 2025
c802d94
Shift-tab focus does not function for breadcrumbs on Tablet Mobile de…
patel-prince Jun 17, 2025
c61b875
Merge branch 'stage' of https://github.com/adobecom/milo into MWPW-17…
patel-prince Jun 17, 2025
e9005da
Merge branch 'stage' of https://github.com/adobecom/milo into MWPW-17…
patel-prince Jun 23, 2025
099011d
Merge branch 'stage' of https://github.com/adobecom/milo into MWPW-17…
patel-prince Jun 25, 2025
71701bf
fix focus fedsnavlinks when sybheader level 3 is present
patel-prince Jun 26, 2025
63fd7d2
focus selected tab on submenu open if focus mode is on
patel-prince Jun 27, 2025
122a1ac
add rtl support
patel-prince Jun 27, 2025
3a33aef
Merge branch 'stage' of https://github.com/adobecom/milo into MWPW-17…
patel-prince Jun 30, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions libs/blocks/global-navigation/utilities/keyboard/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import { getNextVisibleItemPosition, getPreviousVisibleItemPosition, selectors } from './utils.js';
import MainNav from './mainNav.js';
import { closeAllDropdowns, lanaLog, logErrorFor } from '../utilities.js';
import MobileGnav from './mobileGnav.js';

const cycleOnOpenSearch = ({ e, isDesktop }) => {
const withoutBreadcrumbs = [
Expand Down Expand Up @@ -77,6 +78,7 @@ class KeyboardNavigation {
try {
this.addEventListeners();
this.mainNav = new MainNav();
this.mobileGnav = MobileGnav.init();
if (newNavWithLnav) {
this.loadLnavNavigation();
}
Expand Down
126 changes: 126 additions & 0 deletions libs/blocks/global-navigation/utilities/keyboard/mobileGnav.js
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;
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const selectors = {
logo: '.feds-logo',
profileMenu: '.feds-profile-menu',
profile: '.feds-profile',
breadCrumbItems: '.feds-breadcrumbs li > a',
breadCrumbItems: '.feds-breadcrumbs li:not(:nth-last-child(n+3):not(:first-child)) > a',
expandedPopupTrigger: '.feds-navLink[aria-expanded = "true"]',
promoLink: '.feds-promo-link',
imagePromo: 'a.feds-promo-image',
Expand Down
Loading
0