fix(client): add tabindex only to <pre> elements with horizontal scroll for accessibility (#60901)

This commit is contained in:
dev-kamil
2025-09-11 17:24:22 +02:00
committed by GitHub
parent ded6b598d7
commit 7d825d112d

View File

@@ -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');
}
});
}
}, []);