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 16 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
8 changes: 4 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": "",
"Code folding, rows $0 through $1": "",
"Code folding, row $0": "",
"Unfold code": "",
"Fold at row $0": "",
Copy link
Contributor

Choose a reason for hiding this comment

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

if someone was using the old translation keys, what is going to happen? can we at least show a warning? can we support both by deprecating the old one?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

added a warning when a Ace tries to replace a string using the nls function but can't find a translation in the provided messages.

Copy link
Contributor

Choose a reason for hiding this comment

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

Does this mean this is a breaking change? If so, can we avoid it or is it intentional?

"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": "",
"Code folding, rows $0 through $1": "",
"Code folding, row $0": "",
"Unfold code": "",
"Fold at row $0": "",
"Fold code": "",
"Read annotations row $0": "",

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"), "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"), "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"), "Code folding, row 1");
assert.equal(toggler.getAttribute("aria-expanded"), "true");
assert.equal(toggler.getAttribute("title"), "Fold code");
},

tearDown : function() {
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("Code folding, rows $0 through $1", [foldRange.start.row + 1, foldRange.end.row + 1]));
else {
if (fold)
foldWidget.setAttribute("aria-label", nls("Code folding, rows $0 through $1", [fold.start.row + 1, fold.end.row + 1]));
else
foldWidget.setAttribute("aria-label", nls("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
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": "",
"Code folding, rows $0 through $1": "",
"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",
"Code folding, rows $0 through $1": "",
"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": "",
"Code folding, rows $0 through $1": "",
"Code folding, row $0": "",
"Unfold code": "",
"Fold at row $0": "",
"Fold code": "",
"Read annotations row $0": "",
"error": "ошибка",
Expand Down
Loading