From decb6154198105289170303b7434c524eaf9fda8 Mon Sep 17 00:00:00 2001
From: Oyku Yilmaz <12100596+oykuyilmaz@users.noreply.github.com>
Date: Fri, 7 Jul 2023 11:23:15 +0200
Subject: [PATCH] fix(autocomplete): fix a11y violations (#5241)
Accessibility violations for autocompletion popover are fixed.
role=listbox is moved to $textLayer of ace_autocomplete editor to make its direct children have role=option, otherwise there is aria-required-children violation (https://dequeuniversity.com/rules/axe/4.5/aria-required-children?application=axeAPI)
aria-hidden set for textarea of autocomplete popover (there is textarea there since it is an editor instance).
aria-posinset now starts from 1.
---
src/autocomplete/popup.js | 9 +++++----
src/autocomplete_test.js | 8 ++++----
2 files changed, 9 insertions(+), 8 deletions(-)
diff --git a/src/autocomplete/popup.js b/src/autocomplete/popup.js
index 01fd01f04e2..5fd15bc7221 100644
--- a/src/autocomplete/popup.js
+++ b/src/autocomplete/popup.js
@@ -50,8 +50,9 @@ class AcePopup {
popup.renderer.setStyle("ace_autocomplete");
// Set aria attributes for the popup
- popup.renderer.container.setAttribute("role", "listbox");
- popup.renderer.container.setAttribute("aria-label", nls("Autocomplete suggestions"));
+ popup.renderer.$textLayer.element.setAttribute("role", "listbox");
+ popup.renderer.$textLayer.element.setAttribute("aria-label", nls("Autocomplete suggestions"));
+ popup.renderer.textarea.setAttribute("aria-hidden", "true");
popup.setOption("displayIndentGuides", false);
popup.setOption("dragDelay", 150);
@@ -133,12 +134,12 @@ class AcePopup {
dom.addCssClass(selected, "ace_selected");
var ariaId = getAriaId(row);
selected.id = ariaId;
- popup.renderer.container.setAttribute("aria-activedescendant", ariaId);
+ t.element.setAttribute("aria-activedescendant", ariaId);
el.setAttribute("aria-activedescendant", ariaId);
selected.setAttribute("role", "option");
selected.setAttribute("aria-label", popup.getData(row).value);
selected.setAttribute("aria-setsize", popup.data.length);
- selected.setAttribute("aria-posinset", row);
+ selected.setAttribute("aria-posinset", row+1);
selected.setAttribute("aria-describedby", "doc-tooltip");
}
});
diff --git a/src/autocomplete_test.js b/src/autocomplete_test.js
index 2b13d575f3f..11d2f980a98 100644
--- a/src/autocomplete_test.js
+++ b/src/autocomplete_test.js
@@ -48,16 +48,16 @@ module.exports = {
assert.ok(!editor.container.querySelector("style"));
sendKey("a");
- checkInnerHTML('arraysort localalooooooooooooooooooooooooooooong_word local', function() {
+ checkInnerHTML('arraysort localalooooooooooooooooooooooooooooong_word local', function() {
sendKey("rr");
- checkInnerHTML('arraysort local', function() {
+ checkInnerHTML('arraysort local', function() {
sendKey("r");
- checkInnerHTML('arraysort local', function() {
+ checkInnerHTML('arraysort local', function() {
sendKey("Return");
assert.equal(editor.getValue(), "arraysort\narraysort alooooooooooooooooooooooooooooong_word");
editor.execCommand("insertstring", " looooooooooooooooooooooooooooong_");
- checkInnerHTML('alooooooooooooooooooooooooooooong_word local', function() {
+ checkInnerHTML('alooooooooooooooooooooooooooooong_word local', function() {
sendKey("Return");
editor.destroy();
editor.container.remove();