mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-03-02 02:01:39 -05:00
fix(client): add tabindex only to <pre> elements with horizontal scroll for accessibility (#60901)
This commit is contained in:
@@ -27,6 +27,15 @@ function PrismFormatted({
|
||||
if (instructionsRef.current) {
|
||||
Prism.hooks.add('complete', enhancePrismAccessibility);
|
||||
Prism.highlightAllUnder(instructionsRef.current);
|
||||
|
||||
const preElements = instructionsRef.current.querySelectorAll('pre');
|
||||
preElements.forEach((pre: HTMLPreElement) => {
|
||||
if (pre.scrollWidth > pre.clientWidth) {
|
||||
pre.setAttribute('tabIndex', '0');
|
||||
} else {
|
||||
pre.removeAttribute('tabIndex');
|
||||
}
|
||||
});
|
||||
}
|
||||
}, []);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user