Skip to content

Commit 00346fd

Browse files
authored
fix: always set aria-label to text input in a11y mode (#5563)
* fix: always set aria-label to text input in a11y mode
1 parent 2330d80 commit 00346fd

File tree

3 files changed

+26
-8
lines changed

3 files changed

+26
-8
lines changed

src/editor.js

+5
Original file line numberDiff line numberDiff line change
@@ -2939,6 +2939,7 @@ config.defineOptions(Editor.prototype, "editor", {
29392939
// - Prevent tab-trapping.
29402940
// - Hide irrelevant elements from assistive technology.
29412941
// - On Windows, set more lines to the textarea.
2942+
// - set aria-label to the text input.
29422943
if (value){
29432944
this.renderer.enableKeyboardAccessibility = true;
29442945
this.renderer.keyboardFocusClassName = "ace_keyboard-focus";
@@ -2973,6 +2974,10 @@ config.defineOptions(Editor.prototype, "editor", {
29732974
gutterKeyboardHandler = new GutterKeyboardHandler(this);
29742975

29752976
gutterKeyboardHandler.addListener();
2977+
2978+
this.textInput.setAriaOptions({
2979+
setLabel: true
2980+
});
29762981
} else {
29772982
this.renderer.enableKeyboardAccessibility = false;
29782983

src/keyboard/textinput.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -88,15 +88,15 @@ TextInput= function(parentNode, host) {
8888
}
8989
if (options.setLabel) {
9090
text.setAttribute("aria-roledescription", nls("text-input.aria-roledescription", "editor"));
91+
var arialLabel = "";
92+
if (host.$textInputAriaLabel) {
93+
arialLabel += `${host.$textInputAriaLabel}, `;
94+
}
9195
if(host.session) {
9296
var row = host.session.selection.cursor.row;
93-
var arialLabel = "";
94-
if (host.$textInputAriaLabel) {
95-
arialLabel += `${host.$textInputAriaLabel}, `;
96-
}
9797
arialLabel += nls("text-input.aria-label", "Cursor at row $0", [row + 1]);
98-
text.setAttribute("aria-label", arialLabel);
9998
}
99+
text.setAttribute("aria-label", arialLabel);
100100
}
101101
};
102102

src/keyboard/textinput_test.js

+16-3
Original file line numberDiff line numberDiff line change
@@ -760,10 +760,25 @@ module.exports = {
760760
editor.setOption('enableKeyboardAccessibility', true);
761761
editor.renderer.$loop._flush();
762762

763-
editor.focus();
763+
let text = editor.container.querySelector(".ace_text-input");
764+
assert.equal(text.getAttribute("aria-label"), "Cursor at row 1");
765+
},
766+
767+
"test: text input aria label updated on focus": function() {
768+
editor.setValue("x x\ny y", -1);
769+
editor.setOption('enableKeyboardAccessibility', true);
770+
editor.renderer.$loop._flush();
764771

765772
let text = editor.container.querySelector(".ace_text-input");
766773
assert.equal(text.getAttribute("aria-label"), "Cursor at row 1");
774+
775+
editor.focus();
776+
sendEvent("keydown", {key: { code: "ArrowDown", key: "ArrowDown", keyCode: 40}});
777+
editor.renderer.$loop._flush();
778+
779+
editor.blur();
780+
editor.focus();
781+
assert.equal(text.getAttribute("aria-label"), "Cursor at row 2");
767782
},
768783

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

775-
editor.focus();
776-
777790
let text = editor.container.querySelector(".ace_text-input");
778791
assert.equal(text.getAttribute("aria-label"), "super cool editor, Cursor at row 1");
779792
}

0 commit comments

Comments
 (0)