From 7d825d112d26a14d0c679162018bd3d24cbcdf14 Mon Sep 17 00:00:00 2001 From: dev-kamil <54180588+dev-kamil@users.noreply.github.com> Date: Thu, 11 Sep 2025 17:24:22 +0200 Subject: [PATCH] fix(client): add tabindex only to
 elements with
 horizontal scroll for accessibility (#60901)

---
 .../templates/Challenges/components/prism-formatted.tsx  | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/client/src/templates/Challenges/components/prism-formatted.tsx b/client/src/templates/Challenges/components/prism-formatted.tsx
index e95673c1084..f8189939168 100644
--- a/client/src/templates/Challenges/components/prism-formatted.tsx
+++ b/client/src/templates/Challenges/components/prism-formatted.tsx
@@ -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');
+        }
+      });
     }
   }, []);