-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Safari doesn't tab to Prism code block #2695
Comments
@mAAdhaTTah I'm aware of that setting and that's not the issue here, as I have that enabled already. And any regular keyboard user would have that enabled as well. While you're not adding anything to make scrollable areas tabbable by default in Chrome and FireFox, by default areas do not overflow and instead grow to the size of their contents. If Prism is creating a structure and applying styles that create scrollable areas, then I feel it should take on a responsibility to make a good faith effort to make that content accessible. I don't think the fact that scrollable areas are tabbable by default in other browsers lets us off the hook. I haven't tested fully, but I think a quick solution might be to just add a |
That's at least a reasonable principle, so let me look into it. |
Some additional info:
I tested it on my machine and Firefox lets me tab to scrollable code blocks. Chrome and (Chromium) Edge have the problem you described. IE11 also has this problem. |
Interesting, @RunDevelopment. Are you on Windows? I haven't tested on Windows, but on my Mac I don't experience the issue in Chrome or Chromium Edge. Might be the OSs handling key events different for UI elements, not sure. |
Yes, I am using Windows. |
I'm on macOS. This issue also get's flagged by Axe-core:
|
I don't think this is correct for accessibility. Focusable elements should have interactive semantics, but there's nothing about a block of code that inherently is interactive. I've had to modify prism as I started to fail accessibility tests because of this incorrect behaviour. If someone wants to be able to navigate code blocks with the keyboard then this is something they should add in themselves, as this breaks WCAG compliance. |
I disagree. Code blocks often have scroll bars, be it horizontal or vertical. These scroll bars must be interacted with in order to see the full content of a code block. However, in some browsers, this interaction is only possible with the If we made code blocks non-focusable again, we would make it impossible for keyword-users to see the full contents of some code blocks by default. |
Related:
I assume you're getting a failure on Success Criterion 4.1.2 Name, Role, Value (A). This doesn't fail Success Criterion 2.1.1 Keyboard, it actually fixes it. Adding role="region" in combination with the tabindex="0" will handle the Name, Role, Value error. |
According to MDN, landmark roles should be used sparingly. Wouldn't |
Yes but role="generic" still gets flagged as an error on 4.1.2 Name, Role, Value unfortunately. Role="region" does not. |
As role="region" creates an unnamed landmark, it would be good to identify it with an aria-label. Fox example: |
You're confusing the fact that they can have scroll bars with an assumption that they will. This is not always the case. Adding This should be something users add for themselves unless you want to start detecting overflows and adding the attribute only when scroll bars actually appear.
Right now you're making it more difficult for every keyboard user to navigate a site in an incorrect assumption. At the end of the day, blocks of code are not inherently interactive. You cannot be add
No.
If the area is non-interactive, adding |
I don't think it's fair to say that allowing all code blocks to be focusable "blindy breaks" the functionality for a keyboard user. Yes, in cases where the content doesn't overflow it will cause an extra tab stop, but that doesn't mean the page is broken for those users. The spirit of WCAG SC 2.1.1 is that all content CAN be accessed with a keyboard, that doesn't mean that a user necessarily will interact with it. By being consistent and predictable, users will learn that all code blocks are accessible even though a particular one might not require it. To my knowledge, a code block that is focusable but doesn't require scrolling to view the content is not a scenario that fails this SC. Content can change: authors can make edits that now cause a code block to overflow. And users can change their viewing specifics: they can revisit the page on a different device or different size browser window, they might enlarge their text to view something better, or other actions that create overflow where it didn't exist before. So a consistent experience is key. Developers can also mitigate confusion with proper headings and other information paired with the code block, such as "CSS Example 3 (content may overflow)". |
There are pros and cons but I think what PrismJS is now doing, adding tabindex=0 with no role or name, is best for users. Including tabindex removes a barrier for keyboard (and keyboard-equivalent) users to enable access to scrollable codeblocks. Since the tabindex is always present, it does add an unnecessary tab stop to non-scrollable codeblocks for keyboard users but that only makes page navigation a little worse, the trade-off is worth it. If there was a whole set of codeblocks that might not be of interest to all readers, the author could precede the set with a "skip link" or put them all within a disclosure widget (like details-summary elements). In theory, you could have JavaScript checking whether each codeblock is scrollable to add/remove the tabindex attribute (or toggle the value between 0 and -1) but that doesn't sound like a worthwhile trade-off (to develop or to have continually running on every page). Regarding MDN's WCAG Keyboard page, it's not an authoritative source but it is useful. It says "focusable elements should have interactive semantics." A scrollable codeblock is interactive, you can scroll it, but there are no interactive semantics that convey "scrollability." The MDN page says "focusable elements should have interactive semantics" but for other subjects, it uses the word "must," like "interactive elements must be focusable." "Must" is a requirement, "should" is a recommendation or a description of typical situations; this case is an exception, for the reasons I've given. Additionally, in the browsers that are automatically adding a tab stop for scrollable elements, they are not adding any semantics with it; two wrongs don't make a right but they do serve as real-world examples of focusable elements without interactive semantics. If tests are failing on elements solely because they have tabindex=0, the tests should be improved. Adding roles and names to satisfy the tests would benefit only developers and make the user experience worse for some people. |
I was confused about the new tabindex of the pre element to be honest, as when testing keyboard navigation on my site "something" was getting focused, but I didn't know what. So I'm experimentally adding a focus outline to pre elements with tabindex like
I think adding an aria-label to the element would benefit users of screen readers, but that should probably be done manually? Has anyone been researching this, maybe done some accessibility testing? |
Firefox does have a subtle focus outline, so unless you overwrite that, it should be clear which element is focused.
I don't think that we can do that on a library level. The main problem is that screen readers seem to just read out the value of the label. So the screen reader saying "code block" won't help non-English speaking people. |
Thank you @RunDevelopment for your insights. Those are valid points. I fixed my firefox styling to make the focus outline properly, and you're right, an aria label should be descriptive and thus probably added manually - a generic "code block" label is not helping much. |
When using the Safari desktop browser (v14) with a keyboard, Prism blocks don't appear in the tab order. So a keyboard-only user won't be able to tab to the block of code and scroll to view any overflowed content. Chrome, FireFox, and Edge work fine, I'm only seeing this in Safari.
I noticed this while testing a local site, but then checked the examples on Prism's site and I'm having the same issue, so it should be easy to replicate. No plugins or anything of that nature.
To replicate:
The text was updated successfully, but these errors were encountered: