Skip to content

Commit

Permalink
fix: always set aria-label to text input in a11y mode (#5563)
Browse files Browse the repository at this point in the history
* fix: always set aria-label to text input in a11y mode
  • Loading branch information
akoreman authored May 24, 2024
1 parent 2330d80 commit 00346fd
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 8 deletions.
5 changes: 5 additions & 0 deletions src/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -2939,6 +2939,7 @@ config.defineOptions(Editor.prototype, "editor", {
// - Prevent tab-trapping.
// - Hide irrelevant elements from assistive technology.
// - On Windows, set more lines to the textarea.
// - set aria-label to the text input.
if (value){
this.renderer.enableKeyboardAccessibility = true;
this.renderer.keyboardFocusClassName = "ace_keyboard-focus";
Expand Down Expand Up @@ -2973,6 +2974,10 @@ config.defineOptions(Editor.prototype, "editor", {
gutterKeyboardHandler = new GutterKeyboardHandler(this);

gutterKeyboardHandler.addListener();

this.textInput.setAriaOptions({
setLabel: true
});
} else {
this.renderer.enableKeyboardAccessibility = false;

Expand Down
10 changes: 5 additions & 5 deletions src/keyboard/textinput.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,15 +88,15 @@ TextInput= function(parentNode, host) {
}
if (options.setLabel) {
text.setAttribute("aria-roledescription", nls("text-input.aria-roledescription", "editor"));
var arialLabel = "";
if (host.$textInputAriaLabel) {
arialLabel += `${host.$textInputAriaLabel}, `;
}
if(host.session) {
var row = host.session.selection.cursor.row;
var arialLabel = "";
if (host.$textInputAriaLabel) {
arialLabel += `${host.$textInputAriaLabel}, `;
}
arialLabel += nls("text-input.aria-label", "Cursor at row $0", [row + 1]);
text.setAttribute("aria-label", arialLabel);
}
text.setAttribute("aria-label", arialLabel);
}
};

Expand Down
19 changes: 16 additions & 3 deletions src/keyboard/textinput_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -760,10 +760,25 @@ module.exports = {
editor.setOption('enableKeyboardAccessibility', true);
editor.renderer.$loop._flush();

editor.focus();
let text = editor.container.querySelector(".ace_text-input");
assert.equal(text.getAttribute("aria-label"), "Cursor at row 1");
},

"test: text input aria label updated on focus": function() {
editor.setValue("x x\ny y", -1);
editor.setOption('enableKeyboardAccessibility', true);
editor.renderer.$loop._flush();

let text = editor.container.querySelector(".ace_text-input");
assert.equal(text.getAttribute("aria-label"), "Cursor at row 1");

editor.focus();
sendEvent("keydown", {key: { code: "ArrowDown", key: "ArrowDown", keyCode: 40}});
editor.renderer.$loop._flush();

editor.blur();
editor.focus();
assert.equal(text.getAttribute("aria-label"), "Cursor at row 2");
},

"test: text input aria label with extra label set": function() {
Expand All @@ -772,8 +787,6 @@ module.exports = {
editor.setOption('enableKeyboardAccessibility', true);
editor.renderer.$loop._flush();

editor.focus();

let text = editor.container.querySelector(".ace_text-input");
assert.equal(text.getAttribute("aria-label"), "super cool editor, Cursor at row 1");
}
Expand Down

0 comments on commit 00346fd

Please sign in to comment.