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

fix: Improve ARIA labelling fold controls #5205

Merged
merged 21 commits into from
Jun 20, 2023
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
10 changes: 6 additions & 4 deletions demo/i18n.html
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@
"Autocomplete suggestions": "Предложения автозаполнения",

"Cursor at row $0": "",
"Unfold rows $0 to $1": "",
"Toggle code folding, rows $0 through $1": "",
"Toggle code folding, row $0": "",
"Unfold code": "",
"Fold at row $0": "",
"Fold code": "",
"Read annotations row $0": "",

Expand Down Expand Up @@ -109,9 +109,9 @@
"Autocomplete suggestions": "Ավտոմատ լրացման առաջարկներ",

"Cursor at row $0": "",
"Unfold rows $0 to $1": "",
"Toggle code folding, rows $0 through $1": "",
"Toggle code folding, row $0": "",
"Unfold code": "",
"Fold at row $0": "",
"Fold code": "",
"Read annotations row $0": "",

Expand Down Expand Up @@ -147,6 +147,8 @@
"Unfold rows $0 to $1": "Desplegar las filas desde $0 hasta $1",
"Unfold code": "Desplegar el codigo",
"Fold at row $0": "Plegar en fila $0",
"Toggle code folding, rows $0 through $1": "",
"Toggle code folding, row $0": "",
"Fold code": "Plegar el codigo",
"Read annotations row $0": "Leer anotaciones fila $0",
"error": "error",
Expand Down
40 changes: 40 additions & 0 deletions src/keyboard/gutter_handler_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,46 @@ module.exports = {
assert.equal(document.activeElement, lines.cells[1].element.childNodes[2]);
done();
}, 20);
},"test: aria attributes mode with getFoldWidgetRange" : function() {
var editor = this.editor;
var value = "x {" + "\n".repeat(5) + "}";
editor.session.setMode(new Mode());
editor.setOption("enableKeyboardAccessibility", true);
editor.setValue(value, -1);
editor.renderer.$loop._flush();

var lines = editor.renderer.$gutterLayer.$lines;
var toggler = lines.cells[0].element.children[1];

assert.equal(toggler.getAttribute("aria-label"), "Toggle code folding, rows 1 through 6");
assert.equal(toggler.getAttribute("aria-expanded"), "true");
assert.equal(toggler.getAttribute("title"), "Fold code");

editor.session.$toggleFoldWidget(0, {});
editor.renderer.$loop._flush();

assert.equal(toggler.getAttribute("aria-label"), "Toggle code folding, rows 1 through 6");
assert.equal(toggler.getAttribute("aria-expanded"), "false");
assert.equal(toggler.getAttribute("title"), "Unfold code");
},
"test: aria attributes mode without getFoldWidgetRange" : function() {
var editor = this.editor;
var value = "x {" + "\n".repeat(5) + "}";
var mode = new Mode();
mode.foldingRules.getFoldWidgetRange = function(session, foldStyle, row) {
return null;
};
editor.session.setMode(mode);
editor.setOption("enableKeyboardAccessibility", true);
editor.setValue(value, -1);
editor.renderer.$loop._flush();

var lines = editor.renderer.$gutterLayer.$lines;
var toggler = lines.cells[0].element.children[1];

assert.equal(toggler.getAttribute("aria-label"), "Toggle code folding, row 1");
assert.equal(toggler.getAttribute("aria-expanded"), "true");
assert.equal(toggler.getAttribute("title"), "Fold code");
},"test: should signal keyboard event" : function(done) {
var editor = this.editor;
var value = "x {" + "\n".repeat(50) + "}\n";
Expand Down
22 changes: 17 additions & 5 deletions src/layer/gutter.js
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,8 @@ class Gutter{

if (c) {
var foldClass = "ace_fold-widget ace_" + c;
if (c == "start" && row == foldStart && row < fold.end.row){
var isClosedFold = c == "start" && row == foldStart && row < fold.end.row;
if (isClosedFold){
foldClass += " ace_closed";
var foldAnnotationClass = '';
var annotationInFold = false;
Expand Down Expand Up @@ -360,13 +361,24 @@ class Gutter{
// Set a11y properties.
foldWidget.setAttribute("role", "button");
foldWidget.setAttribute("tabindex", "-1");
var fold = session.getFoldLine(rowText - 1);
if (fold) {
foldWidget.setAttribute("aria-label", nls("Unfold rows $0 to $1", [rowText, fold.end.row + 1]));
var foldRange = session.getFoldWidgetRange(row);

// getFoldWidgetRange is optional to be implemented by fold modes, if not available we fall-back.
if (foldRange)
foldWidget.setAttribute("aria-label", nls("Toggle code folding, rows $0 through $1", [foldRange.start.row + 1, foldRange.end.row + 1]));
else {
if (fold)
foldWidget.setAttribute("aria-label", nls("Toggle code folding, rows $0 through $1", [fold.start.row + 1, fold.end.row + 1]));
else
foldWidget.setAttribute("aria-label", nls("Toggle code folding, row $0", [row + 1]));
}

if (isClosedFold) {
foldWidget.setAttribute("aria-expanded", "false");
foldWidget.setAttribute("title", nls("Unfold code"));
}
else {
foldWidget.setAttribute("aria-label", nls("Fold at row $0", [rowText]));
foldWidget.setAttribute("aria-expanded", "true");
foldWidget.setAttribute("title", nls("Fold code"));
}
} else {
Expand Down
3 changes: 3 additions & 0 deletions src/lib/app_config.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,9 @@ class AppConfig {
}

nls(string, params) {
if (messages && !messages[string]) {
warn("No message found for '" + string + "' in the provided messages, falling back to default English message.");
}
var translated = messages && messages[string] || string;
if (params) {
translated = translated.replace(/\$(\$|[\d]+)/g, function(_, name) {
Expand Down
4 changes: 2 additions & 2 deletions translations/am.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
"Search In Selection": "Փնտրել նշվածում",
"$0 of $1": "$1-ից $0",
"Cursor at row $0": "",
"Unfold rows $0 to $1": "",
"Toggle code folding, rows $0 through $1": "",
"Toggle code folding, row $0": "",
"Unfold code": "",
"Fold at row $0": "",
"Fold code": "",
"Read annotations row $0": "",
"error": "սխալ",
Expand Down
4 changes: 2 additions & 2 deletions translations/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
"Search In Selection": "Buscar en la selección",
"$0 of $1": "$0 de $1",
"Cursor at row $0": "Cursor en row $0",
"Unfold rows $0 to $1": "Desplegar las filas desde $0 hasta $1",
"Unfold code": "Desplegar el codigo",
"Fold at row $0": "Plegar en fila $0",
"Toggle code folding, rows $0 through $1": "",
"Toggle code folding, row $0": "",
"Fold code": "Plegar el codigo",
"Read annotations row $0": "Leer anotaciones fila $0",
"error": "error",
Expand Down
4 changes: 2 additions & 2 deletions translations/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
"Search In Selection": "Искать в выделенном",
"$0 of $1": "$0 из $1",
"Cursor at row $0": "",
"Unfold rows $0 to $1": "",
"Toggle code folding, rows $0 through $1": "",
"Toggle code folding, row $0": "",
"Unfold code": "",
"Fold at row $0": "",
"Fold code": "",
"Read annotations row $0": "",
"error": "ошибка",
Expand Down