-
Notifications
You must be signed in to change notification settings - Fork 176
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -402,13 +402,19 @@ class Gnav { | |||||||||||||||||
`; | ||||||||||||||||||
}; | ||||||||||||||||||
|
||||||||||||||||||
removeLocalNav = () => { | ||||||||||||||||||
lanaLog({ message: 'Gnav Localnav was removed, potential CLS' }); | ||||||||||||||||||
document.querySelector('.feds-localnav')?.remove(); | ||||||||||||||||||
return; | ||||||||||||||||||
Comment on lines
+405
to
+408
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [eslint] <no-useless-return> reported by reviewdog 🐶
Suggested change
|
||||||||||||||||||
} | ||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||||||||||||||||||
|
||||||||||||||||||
decorateLocalNav = async () => { | ||||||||||||||||||
if (!this.isLocalNav()) return; | ||||||||||||||||||
if (this.isLocalNav()) this.removeLocalNav(); | ||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should it also return here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It returns from |
||||||||||||||||||
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(); | ||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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'); | ||||||||||||||||||
|
@@ -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(); | ||||||||||||||||||
|
@@ -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 | ||||||||||||||||||
|
There was a problem hiding this comment.
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'.