Skip to content

Conversation

davemackintosh
Copy link
Contributor

@davemackintosh davemackintosh commented Jun 18, 2025

Accessibiity tools can't handle the anchors generated as they retain focus, adding the inert prevents focus on this element and fixes this accessibility issue. Closes #573

@kivikakk kivikakk enabled auto-merge June 18, 2025 10:33
@kivikakk
Copy link
Owner

Thank you very much! 🧡

@davemackintosh
Copy link
Contributor Author

davemackintosh commented Jun 18, 2025

My pleasure, I'll fix those tests. They all passed for me locally so I'll take a look unless you're aware of any specific reason they're failing. they're fixed now.

Accessibiity tools can't handle the anchors generated as they retain
focus, adding the (inert)[https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Global_attributes/inert] prevents focus on this element and fixes this accessibility issue.
auto-merge was automatically disabled June 18, 2025 10:39

Head branch was pushed to by a user without write access

@davemackintosh davemackintosh force-pushed the fix/573-header-id-inert-attribute branch from c29c3a3 to 75f19f6 Compare June 18, 2025 10:39
@davemackintosh
Copy link
Contributor Author

@kivikakk sorry, automerge got disabled when I pushed the fix to the test.

@kivikakk
Copy link
Owner

No problems :) thank you again!!

@kivikakk kivikakk merged commit abee4cd into kivikakk:main Jun 18, 2025
22 checks passed
@digitalmoksha
Copy link
Collaborator

@davemackintosh I'm a little confused by this change. Doesn't this make the header link unusable? From my testing there is no way to grab the link to that specific header.

GitHub doesn't add header links in their issue description/comments, but they do in rendered files, like a README. Today I can hover over the Related projects link in the comrak README and copy it's link so that I can paste it here: https://github.com/kivikakk/comrak#related-projects

But from my testing, inert kills that ability.

Exactly which accessibility tools are having a problem? I do think there are some things that need to get done to make header accessibility better, but I'm not sure this one is correct.

@digitalmoksha
Copy link
Collaborator

digitalmoksha commented Jul 7, 2025

We've been discussing this exact problem over in GitLab (with screen readers, as mentioned in the original issue here #573), where we're seeing the same problem. It's been inactive for a couple months, but we actually need to get back to it.

@kivikakk
Copy link
Owner

kivikakk commented Jul 9, 2025

Thanks for bringing this to our attention, @digitalmoksha!

I am not the target audience for screen readers (my accessibility needs run the "other" way; it's hearing I struggle with), so I will need to rely on your (pl.) experience and connection with users to determine the best solution.

In the meantime, should we revert?

@davemackintosh
Copy link
Contributor Author

It's my understanding that this prevents screen readers from incorrectly jumping about as clicking to the anchor gives the target focus and the inert property prevents the focus. I'm happy to be wrong about this though.

@kivikakk
Copy link
Owner

kivikakk commented Jul 9, 2025

The problem is indeed as @digitalmoksha describes it; the anchor is intended not only as a destination, but a clickable element which links to itself. This permits end-users to get an easy reference to that anchor.

Here's an example as seen on GitHub:

out

With inert, the anchor and anything within it (the 🔗 SVG on GitHub, for instance) cannot receive events and cannot be interacted with.

Might it not be sufficient to set aria-hidden="true" on these anchors instead? This would exclude them and their children from the accessibility tree (as inert does) without affecting their usability from this point of view.

@digitalmoksha
Copy link
Collaborator

The aria-hidden="true" is already added to those links in

"<a inert href=\"#{}\" aria-hidden=\"true\" class=\"anchor\" id=\"{}{}\"></a>",
, so I don't think that's the solution.

There was an idea about putting the text inside the link

Change

<h2 data-sourcepos="5:1-5:18" dir="auto">
  Expected result
  <a href="#expected-result" aria-hidden="true" class="anchor" id="user-content-expected-result">
  </a>
</h2>

to

<h2 data-sourcepos="5:1-5:18" dir="auto">
  <a href="#expected-result" class="anchor" id="user-content-expected-result">
    Expected result
  </a>
</h2>

I don't know if that would fix it or not. I'm failing at really testing this out on my system.

Another idea is was using aria-labelledby on the link, but would require the id to be moved from the <a> to the <h2>

<h2 data-sourcepos="5:1-5:18" dir="auto" id="user-content-expected-result-text">
  <a href="#expected-result" aria-labelledby="user-content-expected-result-text" class="anchor" id="user-content-expected-result">
  </a>
  Expected result
</h2>

@digitalmoksha
Copy link
Collaborator

I do think we will need to revert this while we find a better accessibility solution.

@kivikakk
Copy link
Owner

The aria-hidden="true" is already added to those links

hah. Good on me for checking first.

I will revert. I think we need a clearer idea of what unpleasantness is being caused --- i.e. what actually is happening for screen reader users, as I'm still unclear on what the original issue describes ("can't handle the anchors [...] as they retain focus when you go to them"). Does it mean the reader doesn't continue automatically after following an anchor? (I am assuming this would be desirable.)

I wonder if moving the id to the heading element might be a solution, if it means the anchor doesn't take focus and prevent further reading. But again, I am not the target demographic, I do not use the software in question, and we need discussion with affected users to understand and improve the situation.

kivikakk added a commit that referenced this pull request Jul 10, 2025
This reverts commit 75f19f6.

See discussion at #574 (comment).
@mhanberg
Copy link

In the meantime, you can add this snippet to your website to naively (enhance to your own desire to avoid false positives) remove the inert attribute

document.querySelectorAll("a[inert]").forEach((node) => {
  node.removeAttribute("inert");
});

@digitalmoksha
Copy link
Collaborator

@kivikakk I see you made the revert. Should we cut a new release?

@kivikakk
Copy link
Owner

Indeed :) Done; v0.40.0 (!).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Heading anchors should include the inert property
4 participants