-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Handle normal anchor links as expected #23074
base: 5.x-dev
Are you sure you want to change the base?
Conversation
&& $(`${newUrl.hash},a[name=${newUrl.hash.substring(1)}]`).length | ||
) { | ||
$(`${newUrl.hash},a[name=${newUrl.hash.substring(1)}]`)[0].scrollIntoView(); | ||
window.location.href = event.oldURL; |
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.
Can this have some really ugly side effects? 🤔
For example the inline link for image tracking in the javascript tracking code generator:
matomo/plugins/CoreAdminHome/vue/src/JsTrackingCodeGenerator/JsTrackingCodeGenerator.vue
Lines 213 to 219 in 9a3ef94
jsTrackingIntro4a() { | |
return translate( | |
'CoreAdminHome_JSTrackingIntro4', | |
'<a href="#image-tracking-link">', | |
'</a>', | |
); | |
}, |
The actual section links at the top are always going to #/section
, not just #section
. That one inline link now goes to the actual anchor, and if you have any other section in your hash, like #/react
, the change back to the previous hash will also trigger a scroll to the previous section.
Now this is a simple one to fix (just update the inline anchor link), but maybe there are more places that would actually break when cycling hashes?
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.
Would it make sense to check if the previous hash was something containing =
or &
and only do it in that case? 🤔
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.
Ideally I would say we replace the skip-to-content link with a pure JS implementation: focus the main element, scroll that element into view, don't use any hash manipulation.
If that is sufficient for accessibility we wouldn't need to change any hashes around 🤔
Description:
Normal anchor links currently fully break the application, as Matomo tries to interpret those values as parsable URL. This results in an empty page being loaded.
This PR aims to change that behaviour. Before trying to use any hash value as report URL the system will now check if the hash value looks like an anchor and if an element with an according id (or a link with a name attribute) exists. If that is the case the according element will be scrolled into view. The hash part of the URL will then be reset to the previous value.
fixes #23060
Review