fix(v2): improve accessibility of code blocks (#4943)

This commit is contained in:
Alexey Pyltsyn 2021-06-15 17:28:41 +03:00 committed by GitHub
parent 52f19e15f0
commit dfe32dac9e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 13 deletions

View file

@ -207,13 +207,14 @@ export default function CodeBlock({
</div>
)}
<div className={clsx(styles.codeBlockContent, language)}>
<div
<pre
/* eslint-disable-next-line jsx-a11y/no-noninteractive-tabindex */
tabIndex={0}
className={clsx(className, styles.codeBlock, 'thin-scrollbar', {
[styles.codeBlockWithTitle]: codeBlockTitle,
})}>
<div className={styles.codeBlockLines} style={style}>
})}
style={style}>
<code className={styles.codeBlockLines}>
{tokens.map((line, i) => {
if (line.length === 1 && line[0].content === '') {
line[0].content = '\n'; // eslint-disable-line no-param-reassign
@ -222,19 +223,19 @@ export default function CodeBlock({
const lineProps = getLineProps({line, key: i});
if (highlightLines.includes(i + 1)) {
lineProps.className = `${lineProps.className} docusaurus-highlight-code-line`;
lineProps.className += ' docusaurus-highlight-code-line';
}
return (
<div key={i} {...lineProps}>
<span key={i} {...lineProps}>
{line.map((token, key) => (
<span key={key} {...getTokenProps({token, key})} />
))}
</div>
</span>
);
})}
</div>
</div>
</code>
</pre>
<button
ref={button}