feat: accessibility improvements (#5758)

This commit is contained in:
Nick Perez 2024-11-04 13:49:58 +01:00 committed by GitHub
parent 830e683dde
commit e5228ea6be
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -360,6 +360,11 @@ export class Editor extends EventEmitter<EditorEvents> {
this.view = new EditorView(this.options.element, { this.view = new EditorView(this.options.element, {
...this.options.editorProps, ...this.options.editorProps,
attributes: {
// add `role="textbox"` to the editor element
role: 'textbox',
...this.options.editorProps?.attributes,
},
dispatchTransaction: this.dispatchTransaction.bind(this), dispatchTransaction: this.dispatchTransaction.bind(this),
state: EditorState.create({ state: EditorState.create({
doc, doc,
@ -367,14 +372,6 @@ export class Editor extends EventEmitter<EditorEvents> {
}), }),
}) })
// add `role="textbox"` to the editor element
this.view.dom.setAttribute('role', 'textbox')
// add aria-label to the editor element
if (!this.view.dom.getAttribute('aria-label')) {
this.view.dom.setAttribute('aria-label', 'Rich-Text Editor')
}
// `editor.view` is not yet available at this time. // `editor.view` is not yet available at this time.
// Therefore we will add all plugins and node views directly afterwards. // Therefore we will add all plugins and node views directly afterwards.
const newState = this.state.reconfigure({ const newState = this.state.reconfigure({