Hello,
I have been trying to implement Tab Handling in line with the advice from the example, however I have been struggling to get my notice read by screen readers.
I wrote this simple ViewPlugin which places a hint in a div when the editor has focus (styling omitted for brevity, but it doesn’t touch display or visibility):
const tabEscapePlugin = ViewPlugin.fromClass(
class {
hint: HTMLDivElement;
constructor(view: EditorView) {
this.hint = document.createElement("div");
this.hint.ariaLive = "assertive";
this.hint.classList.add("tab-escape-hint");
view.dom.appendChild(this.hint);
}
destroy() {
this.hint.remove();
}
update(update: ViewUpdate) {
if (update.view.hasFocus) {
this.hint.innerText =
"Editor is focused, press Escape to navigate to other elements using tab.";
} else {
this.hint.innerText = "";
}
}
},
);
However while this works fine visually (the hint appears and disappears when the editor is focused/unfocused), there is never any announcement (tested on macOS using VoiceOver with both Firefox and Safari). While debugging this, I recorded my screen then played it back slowly, and saw that my message was being registered by the screen reader, it was just immediately being interrupted with the first line of code in the document. I’m not sure why this is happening, as my understanding is that assertive alerts shouldn’t get interrupted by ordinary content.
Does anyone have an example of how to implement the guidance in a way that alerts a screen reader? I’ve tried a few variations on this (different aria-live and role values) but have not managed to get a working solution yet. Any help would be greatly appreciated.