From 8d7dfb69392960aba61def982f4bea8f3a5caa70 Mon Sep 17 00:00:00 2001 From: Alice Koreman Date: Wed, 22 May 2024 17:47:42 +0200 Subject: [PATCH] feat: allow users to add arialabel to text input (#5560) * feat: allow users to add arialabel to text input --- ace.d.ts | 1 + src/editor.js | 4 ++++ src/keyboard/textinput.js | 7 ++++++- src/keyboard/textinput_test.js | 23 +++++++++++++++++++++++ 4 files changed, 34 insertions(+), 1 deletion(-) diff --git a/ace.d.ts b/ace.d.ts index d22d3d23572..5bf4e978465 100644 --- a/ace.d.ts +++ b/ace.d.ts @@ -235,6 +235,7 @@ export namespace Ace { relativeLineNumbers: boolean; enableMultiselect: boolean; enableKeyboardAccessibility: boolean; + textInputAriaLabel: string; } export interface SearchOptions { diff --git a/src/editor.js b/src/editor.js index dfde1c8edd4..3b0b4d6c4b8 100644 --- a/src/editor.js +++ b/src/editor.js @@ -3002,6 +3002,10 @@ config.defineOptions(Editor.prototype, "editor", { }, initialValue: false }, + textInputAriaLabel: { + set: function(val) { this.$textInputAriaLabel = val; }, + initialValue: "" + }, customScrollbar: "renderer", hScrollBarAlwaysVisible: "renderer", vScrollBarAlwaysVisible: "renderer", diff --git a/src/keyboard/textinput.js b/src/keyboard/textinput.js index 7a316c21ab5..d1951961a82 100644 --- a/src/keyboard/textinput.js +++ b/src/keyboard/textinput.js @@ -90,7 +90,12 @@ TextInput= function(parentNode, host) { text.setAttribute("aria-roledescription", nls("text-input.aria-roledescription", "editor")); if(host.session) { var row = host.session.selection.cursor.row; - text.setAttribute("aria-label", nls("text-input.aria-label", "Cursor at row $0", [row + 1])); + 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); } } }; diff --git a/src/keyboard/textinput_test.js b/src/keyboard/textinput_test.js index 7d8a3928a34..d35f6e50d4a 100644 --- a/src/keyboard/textinput_test.js +++ b/src/keyboard/textinput_test.js @@ -753,6 +753,29 @@ module.exports = { assert.equal(editor.getValue(), ""); sendEvent("input", {key: {inputType: "historyRedo"}}); assert.equal(editor.getValue(), "x"); + }, + + "test: text input aria label without extra label set": function() { + editor.setValue("x x", -1); + 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 with extra label set": function() { + editor.setValue("x x", -1); + editor.setOption('textInputAriaLabel', "super cool editor"); + 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"); } };