Skip to content

Commit 2fc7ad5

Browse files
committed
Update aria-labels for Autocomplete
1 parent 36c9542 commit 2fc7ad5

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

client/modules/IDE/components/show-hint.js

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,19 @@
227227
}
228228
}
229229

230+
function displayHint(name, type) {
231+
return `<p>\
232+
<span class="${type}-name hint-name">${name}</span>\
233+
<span class="hint-hidden">, </span>\
234+
<span class="hint-type">${type}</span>\
235+
<span class="hint-hidden">, </span>\
236+
<a href="https://p5js.org/reference/#/p5/${name}" role="link" onclick="event.stopPropagation()" target="_blank">\
237+
<span class="hint-hidden">open ${name} reference</span>\
238+
<span aria-hidden="true">&#10132;</span></a></p>`;
239+
}
240+
230241
function Widget(completion, data) {
242+
this.id = "cm-complete-" + Math.floor(Math.random(1e6));
231243
this.completion = completion;
232244
this.data = data;
233245
this.picked = false;
@@ -240,6 +252,7 @@
240252
var hints = this.hints = ownerDocument.createElement("ul");
241253
hints.setAttribute("role", "listbox")
242254
hints.setAttribute("aria-expanded", "true")
255+
hints.id = this.id
243256
var theme = completion.cm.options.theme;
244257
hints.className = "CodeMirror-hints " + theme;
245258
this.selectedHint = data.selectedHint || 0;
@@ -252,14 +265,14 @@
252265
if (cur.className != null) className = cur.className + " " + className;
253266
elt.className = className;
254267
if (i == this.selectedHint) elt.setAttribute("aria-selected", "true")
268+
elt.id = this.id + "-" + i
255269
elt.setAttribute("role", "option")
256270
if (cur.render) cur.render(elt, data, cur);
257271
else {
258272
const e = ownerDocument.createElement('p');
259273
const name = getText(cur);
260274
if (cur.item && cur.item.type) {
261-
cur.displayText = `<span class="${cur.item.type}-name hint-name">${name}</span><span class="hint-type">${cur.item.type}</span>*`;
262-
cur.displayText = cur.displayText.replace('*', `<a href="https://p5js.org/reference/#/p5/${name}" onclick="event.stopPropagation()" target="_blank">&#10132;</a>`);
275+
cur.displayText = displayHint(name, cur.item.type);
263276
}
264277
elt.appendChild(e);
265278
e.outerHTML = cur.displayText || getText(cur);
@@ -288,6 +301,8 @@
288301
var winH = parentWindow.innerHeight || Math.max(ownerDocument.body.offsetHeight, ownerDocument.documentElement.offsetHeight);
289302
container.appendChild(hints);
290303
cm.getInputField().setAttribute("aria-autocomplete", "list")
304+
cm.getInputField().setAttribute("aria-owns", this.id)
305+
cm.getInputField().setAttribute("aria-activedescendant", this.id + "-" + this.selectedHint)
291306

292307
var box = completion.options.moveOnOverlap ? hints.getBoundingClientRect() : new DOMRect();
293308
var scrolls = completion.options.paddingForScrollbar ? hints.scrollHeight > hints.clientHeight + 1 : false;

client/styles/components/_hints.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@
7878
float: right;
7979
margin: 0 calc(2rem + #{5 / $base-font-size}rem) 0 0;
8080
}
81+
82+
.hint-hidden {
83+
@extend %hidden-element;
84+
}
8185

8286
a {
8387
position: absolute;

0 commit comments

Comments
 (0)