Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow users to add arialabel to text input #5560

Merged
merged 2 commits into from
May 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ace.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ export namespace Ace {
relativeLineNumbers: boolean;
enableMultiselect: boolean;
enableKeyboardAccessibility: boolean;
textInputAriaLabel: string;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So I guess nothing is optional here? Although everything is

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah all of the options are marked as mandatory, users using this type will likely have to use Partial<EditorOptions>.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}

export interface SearchOptions {
Expand Down
4 changes: 4 additions & 0 deletions src/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
7 changes: 6 additions & 1 deletion src/keyboard/textinput.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
};
Expand Down
23 changes: 23 additions & 0 deletions src/keyboard/textinput_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
};

Expand Down
Loading