Skip to content

Commit 09a5dd5

Browse files
authored
fix: improve accessible labels for CodeMirror views (#385)
1 parent 66cf992 commit 09a5dd5

4 files changed

Lines changed: 13 additions & 4 deletions

File tree

src/app.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ function App() {
3232
>
3333
<EsquerySelectorInput />
3434
<Editor
35+
ariaLabel="Code Editor"
3536
value={code[language]}
3637
highlightedRanges={
3738
astParseResult.ok

src/components/ast/index.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,5 +40,11 @@ export const AST: FC = () => {
4040
);
4141
}
4242

43-
return <Editor readOnly value={JSON.stringify(result.ast, null, 2)} />;
43+
return (
44+
<Editor
45+
ariaLabel="AST JSON"
46+
readOnly
47+
value={JSON.stringify(result.ast, null, 2)}
48+
/>
49+
);
4450
};

src/components/editor.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,15 @@ const languageExtensions: Record<
2828
};
2929

3030
type EditorProperties = {
31+
ariaLabel: string;
3132
readOnly?: boolean;
3233
value?: string;
3334
highlightedRanges?: SourceRange[];
3435
onChange?: (value: string) => void;
3536
};
3637

3738
export const Editor: FC<EditorProperties> = ({
39+
ariaLabel,
3840
readOnly,
3941
value,
4042
highlightedRanges = [],
@@ -55,11 +57,12 @@ export const Editor: FC<EditorProperties> = ({
5557
() => [
5658
activeLanguageExtension,
5759
wrap ? EditorView.lineWrapping : [],
60+
EditorView.contentAttributes.of({ "aria-label": ariaLabel }),
5861
ESLintPlaygroundTheme,
5962
ESLintPlaygroundHighlightStyle,
6063
highlightedRangesExtension(highlightedRanges),
6164
],
62-
[activeLanguageExtension, wrap, highlightedRanges],
65+
[activeLanguageExtension, wrap, ariaLabel, highlightedRanges],
6366
);
6467

6568
const debouncedOnChange = useMemo(
@@ -173,7 +176,6 @@ export const Editor: FC<EditorProperties> = ({
173176
</div>
174177
)}
175178
<CodeMirror
176-
aria-label="Code Editor"
177179
className="h-full overflow-auto scrollbar-thumb scrollbar-track text-sm"
178180
value={value}
179181
extensions={editorExtensions}

src/components/path/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ export const CodePath: FC = () => {
9191
const codePath = extracted.codePathList[index].dot;
9292

9393
if (pathView === "code") {
94-
return <Editor readOnly value={codePath} />;
94+
return <Editor ariaLabel="Code Path" readOnly value={codePath} />;
9595
}
9696

9797
return (

0 commit comments

Comments
 (0)