Skip to content

Commit

Permalink
Merge pull request #5403 from akoreman/completion_a11y
Browse files Browse the repository at this point in the history
fix: set completion popup role to 'menu' for safari
  • Loading branch information
akoreman authored Nov 28, 2023
2 parents 1c207c9 + fbcb850 commit ee917cf
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
9 changes: 7 additions & 2 deletions src/autocomplete/popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ var event = require("../lib/event");
var lang = require("../lib/lang");
var dom = require("../lib/dom");
var nls = require("../config").nls;
var userAgent = require("./../lib/useragent");

var getAriaId = function(index) {
return `suggest-aria-id:${index}`;
Expand Down Expand Up @@ -50,7 +51,8 @@ class AcePopup {
popup.renderer.setStyle("ace_autocomplete");

// Set aria attributes for the popup
popup.renderer.$textLayer.element.setAttribute("role", "listbox");
popup.renderer.$textLayer.element.setAttribute("role", userAgent.isSafari ? "menu" : "listbox");
popup.renderer.$textLayer.element.setAttribute("aria-roledescription", nls("Autocomplete suggestions"));
popup.renderer.$textLayer.element.setAttribute("aria-label", nls("Autocomplete suggestions"));
popup.renderer.textarea.setAttribute("aria-hidden", "true");

Expand Down Expand Up @@ -128,6 +130,7 @@ class AcePopup {
if (selected !== t.selectedNode && t.selectedNode) {
dom.removeCssClass(t.selectedNode, "ace_selected");
el.removeAttribute("aria-activedescendant");
selected.removeAttribute("aria-selected");
t.selectedNode.removeAttribute("id");
}
t.selectedNode = selected;
Expand All @@ -137,11 +140,13 @@ class AcePopup {
selected.id = ariaId;
t.element.setAttribute("aria-activedescendant", ariaId);
el.setAttribute("aria-activedescendant", ariaId);
selected.setAttribute("role", "option");
selected.setAttribute("role", userAgent.isSafari ? "menuitem" : "option");
selected.setAttribute("aria-roledescription", nls("item"));
selected.setAttribute("aria-label", popup.getData(row).value);
selected.setAttribute("aria-setsize", popup.data.length);
selected.setAttribute("aria-posinset", row+1);
selected.setAttribute("aria-describedby", "doc-tooltip");
selected.setAttribute("aria-selected", "true");
}
});
var hideHoverMarker = function() { setHoverMarker(-1); };
Expand Down
8 changes: 4 additions & 4 deletions src/autocomplete_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,16 +66,16 @@ module.exports = {
assert.ok(!editor.container.querySelector("style"));

sendKey("a");
checkInnerHTML('<d "ace_line ace_selected" id="suggest-aria-id:0" role="option" aria-label="arraysort" aria-setsize="2" aria-posinset="1" aria-describedby="doc-tooltip"><s "ace_completion-highlight">a</s><s "ace_">rraysort</s><s "ace_completion-spacer"> </s><s "ace_completion-meta">local</s></d><d "ace_line"><s "ace_completion-highlight">a</s><s "ace_">looooooooooooooooooooooooooooong_word</s><s "ace_completion-spacer"> </s><s "ace_completion-meta">local</s></d>', function() {
checkInnerHTML('<d "ace_line ace_selected" id="suggest-aria-id:0" role="option" aria-roledescription="item" aria-label="arraysort" aria-setsize="2" aria-posinset="1" aria-describedby="doc-tooltip" aria-selected="true"><s "ace_completion-highlight">a</s><s "ace_">rraysort</s><s "ace_completion-spacer"> </s><s "ace_completion-meta">local</s></d><d "ace_line"><s "ace_completion-highlight">a</s><s "ace_">looooooooooooooooooooooooooooong_word</s><s "ace_completion-spacer"> </s><s "ace_completion-meta">local</s></d>', function() {
sendKey("rr");
checkInnerHTML('<d "ace_line ace_selected" id="suggest-aria-id:0" role="option" aria-label="arraysort" aria-setsize="1" aria-posinset="1" aria-describedby="doc-tooltip"><s "ace_completion-highlight">arr</s><s "ace_">aysort</s><s "ace_completion-spacer"> </s><s "ace_completion-meta">local</s></d>', function() {
checkInnerHTML('<d "ace_line ace_selected" id="suggest-aria-id:0" role="option" aria-roledescription="item" aria-label="arraysort" aria-setsize="1" aria-posinset="1" aria-describedby="doc-tooltip" aria-selected="true"><s "ace_completion-highlight">arr</s><s "ace_">aysort</s><s "ace_completion-spacer"> </s><s "ace_completion-meta">local</s></d>', function() {
sendKey("r");
checkInnerHTML('<d "ace_line ace_selected" id="suggest-aria-id:0" role="option" aria-label="arraysort" aria-setsize="1" aria-posinset="1" aria-describedby="doc-tooltip"><s "ace_completion-highlight">arr</s><s "ace_">ayso</s><s "ace_completion-highlight">r</s><s "ace_">t</s><s "ace_completion-spacer"> </s><s "ace_completion-meta">local</s></d>', function() {
checkInnerHTML('<d "ace_line ace_selected" id="suggest-aria-id:0" role="option" aria-roledescription="item" aria-label="arraysort" aria-setsize="1" aria-posinset="1" aria-describedby="doc-tooltip" aria-selected="true"><s "ace_completion-highlight">arr</s><s "ace_">ayso</s><s "ace_completion-highlight">r</s><s "ace_">t</s><s "ace_completion-spacer"> </s><s "ace_completion-meta">local</s></d>', function() {

sendKey("Return");
assert.equal(editor.getValue(), "arraysort\narraysort alooooooooooooooooooooooooooooong_word");
editor.execCommand("insertstring", " looooooooooooooooooooooooooooong_");
checkInnerHTML('<d "ace_line ace_selected" id="suggest-aria-id:0" role="option" aria-label="alooooooooooooooooooooooooooooong_word" aria-setsize="1" aria-posinset="1" aria-describedby="doc-tooltip"><s "ace_">a</s><s "ace_completion-highlight">looooooooooooooooooooooooooooong_</s><s "ace_">word</s><s "ace_completion-spacer"> </s><s "ace_completion-meta">local</s></d>', function() {
checkInnerHTML('<d "ace_line ace_selected" id="suggest-aria-id:0" role="option" aria-roledescription="item" aria-label="alooooooooooooooooooooooooooooong_word" aria-setsize="1" aria-posinset="1" aria-describedby="doc-tooltip" aria-selected="true"><s "ace_">a</s><s "ace_completion-highlight">looooooooooooooooooooooooooooong_</s><s "ace_">word</s><s "ace_completion-spacer"> </s><s "ace_completion-meta">local</s></d>', function() {
sendKey("Return");
editor.destroy();
editor.container.remove();
Expand Down
2 changes: 2 additions & 0 deletions src/lib/useragent.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ exports.isWebKit = parseFloat(ua.split("WebKit/")[1]) || undefined;

exports.isChrome = parseFloat(ua.split(" Chrome/")[1]) || undefined;

exports.isSafari = parseFloat(ua.split(" Safari/")[1]) && !exports.isChrome || undefined;

exports.isEdge = parseFloat(ua.split(" Edge/")[1]) || undefined;

exports.isAIR = ua.indexOf("AdobeAIR") >= 0;
Expand Down

0 comments on commit ee917cf

Please sign in to comment.