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

Handle normal anchor links as expected #23074

Open
wants to merge 2 commits into
base: 5.x-dev
Choose a base branch
from
Open

Handle normal anchor links as expected #23074

wants to merge 2 commits into from

Conversation

sgiehl
Copy link
Member

@sgiehl sgiehl commented Feb 25, 2025

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

@sgiehl sgiehl requested a review from a team February 26, 2025 15:12
@sgiehl sgiehl added the c: Accessibility When something is not usable for a certain group (eg missing contrast) or devices (eg smartphones). label Feb 26, 2025
@sgiehl sgiehl marked this pull request as ready for review February 26, 2025 15:13
&& $(`${newUrl.hash},a[name=${newUrl.hash.substring(1)}]`).length
) {
$(`${newUrl.hash},a[name=${newUrl.hash.substring(1)}]`)[0].scrollIntoView();
window.location.href = event.oldURL;
Copy link
Member

@mneudert mneudert Feb 26, 2025

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:

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?

Copy link
Member Author

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? 🤔

Copy link
Member

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 🤔

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c: Accessibility When something is not usable for a certain group (eg missing contrast) or devices (eg smartphones).
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug] Accessibility: Skip to content broken
3 participants