Skip to content

Commit 67e4087

Browse files
committed
Add screen reader announcements for Reset, Run, and Stop sketch actions within code blocks
1 parent adfb46f commit 67e4087

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/components/CodeEmbed/index.jsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { useState, useEffect, useRef } from "preact/hooks";
2+
import { useLiveRegion } from '../hooks/useLiveRegion';
23
import CodeMirror, { EditorView } from "@uiw/react-codemirror";
34
import { javascript } from "@codemirror/lang-javascript";
45
import { cdnLibraryUrl, cdnSoundUrl } from "@/src/globals/globals";
@@ -25,6 +26,7 @@ import { Icon } from "../Icon";
2526
* }
2627
*/
2728
export const CodeEmbed = (props) => {
29+
const { ref: liveRegionRef, announce } = useLiveRegion();
2830
const [rendered, setRendered] = useState(false);
2931
const initialCode = props.initialValue ?? "";
3032
// Source code from Google Docs sometimes uses a unicode non-breaking space
@@ -59,6 +61,7 @@ export const CodeEmbed = (props) => {
5961
} else {
6062
setPreviewCodeString(codeString);
6163
}
64+
announce("Sketch is running");
6265
};
6366

6467
const [previewCodeString, setPreviewCodeString] = useState(codeString);
@@ -108,6 +111,7 @@ export const CodeEmbed = (props) => {
108111
className="bg-bg-gray-40"
109112
onClick={() => {
110113
setPreviewCodeString("");
114+
announce("Sketch stopped");
111115
}}
112116
ariaLabel="Stop sketch"
113117
>
@@ -148,6 +152,7 @@ export const CodeEmbed = (props) => {
148152
onClick={() => {
149153
setCodeString(initialCode);
150154
setPreviewCodeString(initialCode);
155+
announce("Code reset to initial value.");
151156
}}
152157
ariaLabel="Reset code to initial value"
153158
className="bg-white text-black"
@@ -156,6 +161,7 @@ export const CodeEmbed = (props) => {
156161
</CircleButton>
157162
</div>
158163
</div>
164+
<span ref={liveRegionRef} aria-live="polite" class="sr-only" />
159165
</div>
160166
);
161167
};

0 commit comments

Comments
 (0)