Skip to content

Commit 8d7dfb6

Browse files
authored
feat: allow users to add arialabel to text input (#5560)
* feat: allow users to add arialabel to text input
1 parent 36353db commit 8d7dfb6

File tree

4 files changed

+34
-1
lines changed

4 files changed

+34
-1
lines changed

ace.d.ts

+1
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,7 @@ export namespace Ace {
235235
relativeLineNumbers: boolean;
236236
enableMultiselect: boolean;
237237
enableKeyboardAccessibility: boolean;
238+
textInputAriaLabel: string;
238239
}
239240

240241
export interface SearchOptions {

src/editor.js

+4
Original file line numberDiff line numberDiff line change
@@ -3002,6 +3002,10 @@ config.defineOptions(Editor.prototype, "editor", {
30023002
},
30033003
initialValue: false
30043004
},
3005+
textInputAriaLabel: {
3006+
set: function(val) { this.$textInputAriaLabel = val; },
3007+
initialValue: ""
3008+
},
30053009
customScrollbar: "renderer",
30063010
hScrollBarAlwaysVisible: "renderer",
30073011
vScrollBarAlwaysVisible: "renderer",

src/keyboard/textinput.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,12 @@ TextInput= function(parentNode, host) {
9090
text.setAttribute("aria-roledescription", nls("text-input.aria-roledescription", "editor"));
9191
if(host.session) {
9292
var row = host.session.selection.cursor.row;
93-
text.setAttribute("aria-label", nls("text-input.aria-label", "Cursor at row $0", [row + 1]));
93+
var arialLabel = "";
94+
if (host.$textInputAriaLabel) {
95+
arialLabel += `${host.$textInputAriaLabel}, `;
96+
}
97+
arialLabel += nls("text-input.aria-label", "Cursor at row $0", [row + 1]);
98+
text.setAttribute("aria-label", arialLabel);
9499
}
95100
}
96101
};

src/keyboard/textinput_test.js

+23
Original file line numberDiff line numberDiff line change
@@ -753,6 +753,29 @@ module.exports = {
753753
assert.equal(editor.getValue(), "");
754754
sendEvent("input", {key: {inputType: "historyRedo"}});
755755
assert.equal(editor.getValue(), "x");
756+
},
757+
758+
"test: text input aria label without extra label set": function() {
759+
editor.setValue("x x", -1);
760+
editor.setOption('enableKeyboardAccessibility', true);
761+
editor.renderer.$loop._flush();
762+
763+
editor.focus();
764+
765+
let text = editor.container.querySelector(".ace_text-input");
766+
assert.equal(text.getAttribute("aria-label"), "Cursor at row 1");
767+
},
768+
769+
"test: text input aria label with extra label set": function() {
770+
editor.setValue("x x", -1);
771+
editor.setOption('textInputAriaLabel', "super cool editor");
772+
editor.setOption('enableKeyboardAccessibility', true);
773+
editor.renderer.$loop._flush();
774+
775+
editor.focus();
776+
777+
let text = editor.container.querySelector(".ace_text-input");
778+
assert.equal(text.getAttribute("aria-label"), "super cool editor, Cursor at row 1");
756779
}
757780
};
758781

0 commit comments

Comments
 (0)