-
-
Notifications
You must be signed in to change notification settings - Fork 8.5k
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
Enhancement: improved the accessibility of codeblocks #3178
Conversation
Deploy preview for docusaurus-2 ready! Built with commit 03c47eb |
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.
Unfortunately, this change seems to totally break Docusaurus 2 website code blocks.
https://deploy-preview-3178--docusaurus-2.netlify.app/build/docs/next/markdown-features#code-title
Wow! I'm going to look into this thanks! |
It has been resolved! Since the goal is to ensure screen readers do not read codeblocks I have added aria-hidden="true" attribute to the span tag and It worked! |
Thanks
I'm not very familiar with accessibility, do you have an authority link
that claims this aria attribute on code blocks is a good practice?
Le sam. 1 août 2020 à 16:48, Isaiah Awotide <[email protected]> a
écrit :
… It has been resolved! Since the goal is to ensure screen readers do not
read codeblocks I have added aria-hidden="true" attribute to the span tag
and It worked!
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#3178 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAFW6PREX54MFLZRMKVGNWTR6QTMNANCNFSM4PQMAHLQ>
.
|
I feel removing codeblocks from accessibility tree could help solve the problem as written in the guide above. I'm also relatively new to accessibility API but if you have a better way to go about it, I'd be glad to implement it. Thank you. |
I'm not either an accessibility expert. If you know a dev website that care a lot about accessibility, maybe we can check how they handle the code blocks and ask them for feedback. |
@McZenith it looks to me we should just use
|
packages/docusaurus-theme-classic/src/theme/CodeBlock/index.tsx
Outdated
Show resolved
Hide resolved
@@ -21,9 +21,13 @@ export default ({children, className}) => { | |||
{({style, tokens, getLineProps, getTokenProps}) => ( | |||
<pre className={className} style={{...style, padding: '20px'}}> |
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.
here we have pre, but we should add code too I think
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.
Thank you @slorber, I will look into it and make necessary changes... I really appreciate your help and I just learnt something new...
@slorber Thanks for your guide this far. I really enjoyed the ride... I know it's not easy dealing with a newcomer but you helped me out and here it is, done... Thank you... |
np, happy to help you :) |
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.
padding: '0px', | ||
whiteSpace: 'pre-wrap', | ||
wordBreak: 'break-word', | ||
}}> |
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.
We should use the css module styles instead of inline styles
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.
Oh, okay! Copy that! Next commit in a jiffy. Thank you.
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.
Done!!!
I looked at the code, it doesn't look bad. |
}}> | ||
<code style={{...style, padding: '20px', display: 'inline-flex'}}> | ||
{tokens.map((line, i) => ( | ||
<div |
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.
The only thing I don't like is that in the code div tag. It doesn't seem to be valid. Try it on:
https://validator.w3.org/nu/#textarea
<!DOCTYPE html >
<html lang="en">
<head><title>d</title></head>
<body>
<pre>
<code>
<div><span>werwer</span> </div>
<div><span>werwer</span> </div>
</code>
</pre>
</body>
</html>
Output:
Error: Element div not allowed as child of element code in this context. (Suppressing further errors from this subtree.)
From line 9, column 15; to line 9, column 19
<div><span>
Contexts in which element div may be used:
Where flow content is expected.
As a child of a dl element.
Content model for element code:
Phrasing content.
Phrasing content: https://html.spec.whatwg.org/multipage/dom.html#phrasing-content-2
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.
Ohw okay, I will look into it and see what I can do. I initially didn't include it but I noticed the code highlights were not functioning properly. So I added it and it worked as expected.
Also, I'm not sure if the text is clearly visible here. This does not apply to this pr. But it's worth checking out as accessibility issue. |
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.
bootstrap theme has inline styles
whiteSpace: 'pre-wrap', | ||
wordBreak: 'break-word', | ||
}}> | ||
<code style={{...style, padding: '20px', display: 'inline-flex'}}> |
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.
still has inline styles here
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.
done! All solved!
</div> | ||
<pre className={styles.preTag}> | ||
<code className={styles.codeTag}> | ||
<div key={i} {...lineProps}> |
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.
this is still not valid html
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.
And I think a comment is needed on why exactly pre>code>span
is done here in the code, in both places, since this is not covered by tests, this is the only way to guarantee validity in the future.
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.
thanks, I'm not an expert but why is this not valid?
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.
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.
@slorber I would still recommend setting up tests to check accessibility and validity. Any mistakes can be critical for those who care.
In addition, it is often useful for correct indexing, the search on the site is of course important, but when the developer does not know something, he usually uses google to search, and internal search is the second step.
It may be worth asking the community for help in this matter. And to do it so that it is really seen.
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.
how can we setup accessibility and validity tests? how do we ask for such help to the community for you?
I don't know much about these topics but any help is definitively welcome
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.
Thanks, but still not good 🤪
These 2 pages are still different:
https://deploy-preview-3178--docusaurus-2.netlify.app/build/docs/next/markdown-features
https://v2.docusaurus.io/docs/next/markdown-features
This PR is about accessibility, not design, so the expected result is to have improved accessibility, yet keeping the EXACT same design. Here the new design is different, and looks worst to me.
Closing due to inactivity |
solves #3119
As highlighted at #3119 Changing code block from initial span to code HTML tag improves accessibility for screen readers most especially.