Skip to content

Commit b846a2a

Browse files
authored
Move accessibility attributes to contentDOM (#1334)
1 parent 01db168 commit b846a2a

3 files changed

Lines changed: 39 additions & 1 deletion

File tree

CoreEditor/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
</script>
3434
</head>
3535
<body>
36-
<div id="editor" role="textbox" aria-multiline="true"></div>
36+
<div id="editor"></div>
3737
<script type=module src="./index.ts"></script>
3838
</body>
3939
</html>

CoreEditor/src/extensions.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,12 @@ export function extensions(options: { lineBreak?: string }) {
160160
wordTokenizer(),
161161
interceptInputs(),
162162
observeChanges(),
163+
164+
// Accessibility
165+
EditorView.contentAttributes.of({
166+
'role': 'textbox',
167+
'aria-multiline': 'true',
168+
}),
163169
];
164170
}
165171

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { describe, expect, test } from '@jest/globals';
2+
import { EditorView } from '@codemirror/view';
3+
import * as editor from './utils/editor';
4+
5+
describe('Accessibility test suite', () => {
6+
test('test contentDOM has role textbox', () => {
7+
editor.setUp('', EditorView.contentAttributes.of({
8+
'role': 'textbox',
9+
'aria-multiline': 'true',
10+
}));
11+
12+
const contentDOM = window.editor.contentDOM;
13+
expect(contentDOM.getAttribute('role')).toBe('textbox');
14+
});
15+
16+
test('test contentDOM has aria-multiline', () => {
17+
editor.setUp('', EditorView.contentAttributes.of({
18+
'role': 'textbox',
19+
'aria-multiline': 'true',
20+
}));
21+
22+
const contentDOM = window.editor.contentDOM;
23+
expect(contentDOM.getAttribute('aria-multiline')).toBe('true');
24+
});
25+
26+
test('test contentDOM is contenteditable', () => {
27+
editor.setUp('');
28+
29+
const contentDOM = window.editor.contentDOM;
30+
expect(contentDOM.getAttribute('contenteditable')).toBe('true');
31+
});
32+
});

0 commit comments

Comments
 (0)