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

Scrollable <pre> elements should be focusable for WCAG 2.1 compliance #428

Closed
kevinleedrum opened this issue Jan 31, 2023 · 4 comments
Closed
Labels
bug Something isn't working

Comments

@kevinleedrum
Copy link
Contributor

kevinleedrum commented Jan 31, 2023

As mentioned in #220, scrollable <pre> elements should have tabindex="0" to allow them to be focusable. Right now, these elements will fail WCAG audits if/when they become scrollable. https://www.w3.org/WAI/standards-guidelines/act/rules/0ssw9k/proposed/

It seems ideal to me to make this the default rather than try to update consumers like remark-shiki, etc. to pass in a custom pre.

I wouldn't expect this to be a breaking change since anyone who is already providing a tabindex will already be passing in an entirely custom pre template literal that will override this default.

@OliverSpeir
Copy link

OliverSpeir commented Jan 21, 2024

This results in tabindex applied to all code blocks which is in fact not WCAG compliant. It should only add tabindex when the codeblock is scrollable, but this of course would be difficult to know based on screen size etc. Maybe it's better to leave it up to the user to add tabindex themself

Edit: upon further research having tabindex on non interactive element does not create an explicit WCAG violation AFAIK

@aryanjha256
Copy link

maybe we can add overflow to all <pre /> elements if user opts not to wrap the code so that it won't create an accessibility issue.

@kevinleedrum
Copy link
Contributor Author

The spec defines scrollable as having a scroll distance (e.g. the difference between the scrollWidth and clientWidth), so for elements that can be resized, you are pretty much forced to set up a ResizeObserver or at least a resize event listener to add or remove the tabindex.

I would argue that it's best to default to having the tabindex, so that if JavaScript is disabled or fails, all scrollable elements are still navigable by keyboard users. They just might have some extra unnecessary tab stops that JavaScript would have otherwise removed.

@kevinleedrum
Copy link
Contributor Author

Chrome has announced that they are going to implement keyboard-focusable scrollers at the browser level. In the context of this issue, that would mean the tabindex would no longer be necessary in Chrome since the tab stop would be added automatically. Firefox already does this, and Chrome has tried to implement it before.

However, I have not heard anything about Safari adding this, so even if this lands in Chrome stable, having the occasionally unnecessary tabindex is still a good idea in my opinion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants