Skip to content
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

Local nav should be displayed when the first element is dropdown #3465

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
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
16 changes: 11 additions & 5 deletions libs/blocks/global-navigation/global-navigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -402,13 +402,19 @@ class Gnav {
`;
};

removeLocalNav = () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [eslint] <class-methods-use-this> reported by reviewdog 🐶
Expected 'this' to be used by class method 'removeLocalNav'.

lanaLog({ message: 'Gnav Localnav was removed, potential CLS' });
document.querySelector('.feds-localnav')?.remove();
return;
Comment on lines +405 to +408
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [eslint] <no-useless-return> reported by reviewdog 🐶
Unnecessary return statement.

Suggested change
removeLocalNav = () => {
lanaLog({ message: 'Gnav Localnav was removed, potential CLS' });
document.querySelector('.feds-localnav')?.remove();
return;
removeLocalNav = () => {
lanaLog({ message: 'Gnav Localnav was removed, potential CLS' });
document.querySelector('.feds-localnav')?.remove();

}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [eslint] <semi> reported by reviewdog 🐶
Missing semicolon.

Suggested change
}
};


decorateLocalNav = async () => {
if (!this.isLocalNav()) return;
if (this.isLocalNav()) this.removeLocalNav();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should it also return here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It returns from removeLocalNav function

const localNavItems = this.elements.navWrapper.querySelector('.feds-nav').querySelectorAll('.feds-navItem:not(.feds-navItem--section, .feds-navItem--mobile-only)');
const firstElem = localNavItems[0]?.querySelector('a');
const firstElem = localNavItems[0]?.querySelector('a') || localNavItems[0]?.querySelector('button');
if (!firstElem) {
lanaLog({ message: 'GNAV: Incorrect authoring of localnav found.', tags: 'errorType=info,module=gnav' });
return;
this.removeLocalNav();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and return here as well? That way it'll be less confusing to read and modify the logic below.

}
const [title, navTitle = ''] = this.getOriginalTitle(firstElem);
let localNav = document.querySelector('.feds-localnav');
Expand All @@ -428,7 +434,7 @@ class Gnav {

localNavItems.forEach((elem, idx) => {
const clonedItem = elem.cloneNode(true);
const link = clonedItem.querySelector('a');
const link = clonedItem.querySelector('a') || localNavItems[0]?.querySelector('button');

if (idx === 0) {
localNav.querySelector('.feds-localnav-title').innerText = title.trim();
Expand Down Expand Up @@ -456,7 +462,7 @@ class Gnav {
const promo = document.querySelector('.feds-promo-aside-wrapper');
if (promo) localNav.classList.add('has-promo');
this.elements.localNav = localNav;
localNavItems[0].querySelector('a').textContent = title.trim();
firstElem.textContent = title.trim();
const isAtTop = () => {
const rect = this.elements.localNav.getBoundingClientRect();
// note: ios safari changes between -0.34375, 0, and 0.328125
Expand Down
Loading