-
Notifications
You must be signed in to change notification settings - Fork 174
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
Excluding modals from Active link check #1942
Changes from 1 commit
c4c8034
31d3db6
f4f089d
3a798d2
b213f7b
18137cc
d2a4a7f
5573b92
a4b6cec
b22874b
437e22a
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 |
---|---|---|
|
@@ -247,7 +247,11 @@ export const [hasActiveLink, setActiveLink, getActiveLink] = (() => { | |
|
||
[`${origin}${pathname}`, pathname].forEach((path) => { | ||
if (activeLink) return; | ||
activeLink = area.querySelector(`a[href = '${path}'], a[href ^= '${path}?'], a[href ^= '${path}#']`); | ||
const linkElements = area.querySelectorAll('a:not([data-modal-hash])'); | ||
activeLink = [...linkElements].find((el) => { | ||
const regex = new RegExp(`^${path}(\\?[^#]*)?(#.*)?$`); | ||
return regex.test(el.href); | ||
}); | ||
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. This could be simplified if
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 even a little further, since it doesn't need the return for the inner arrow function
|
||
}); | ||
|
||
if (!activeLink) return null; | ||
|
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.
With this new approach, I'd test a bit more to justify the necessity of the
pathname
check. Say we have the following element:<a href="/path/to/page">Page</a>
. We needed thepathname
check for the query selector, which would have beena[href = '/path/to/page']
. So we were checking an attribute value, which could have been either a full URL or just a path. Moving to theel.href
approach,pathname
might be irrelevant, as its result would always be a full URL.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.
Yes, I agree. I will make the necessary change and update the PR.