Skip to content

Commit 3692cd7

Browse files
ARIA activedescendant, label
1 parent de63b80 commit 3692cd7

File tree

5 files changed

+32
-2
lines changed

5 files changed

+32
-2
lines changed

lib/clear-suggestions.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@ function clearSuggestions(state) {
66
state.selectedIndex = -1;
77
removeListElement(state);
88
state.input.removeAttribute("aria-controls");
9+
state.input.removeAttribute("aria-activedescendant");
910
state.plete.setAttribute("aria-expanded", "false");
1011
}

lib/highlight.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ function highlight(state, index) {
55
const item = state.list.querySelectorAll("plete-item")[index];
66
if (item) {
77
item.classList.add("highlight");
8+
state.input.setAttribute("aria-activedescendant", item.id);
89
}
910
}
1011
}

lib/render-item.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ function renderItem(state, value) {
88
const attrValue = valueIsString ? value : value.id;
99
const label = valueIsString ? value : value.label;
1010

11+
item.setAttribute("aria-label", `Choice: ${label}.`);
1112
item.setAttribute("value", attrValue);
1213
item.setAttribute("title", label);
1314

lib/render.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ function render(state, data) {
99
addListElement(state, select);
1010
const boundRenderItem = renderItem.bind(null, state);
1111

12-
data.map(boundRenderItem).forEach(function(item) {
12+
data.map(boundRenderItem).forEach(function(item, idx) {
13+
item.id = `plete-item-${idx}`;
1314
state.list.appendChild(item);
1415
});
1516

test/aria-support.test.js

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { assert } from "@sinonjs/referee-sinon";
1+
import { assert, refute } from "@sinonjs/referee-sinon";
22
import { fireEvent, waitForElement } from "@testing-library/dom";
33
import { setupTest } from "./test-helper";
44

@@ -47,6 +47,32 @@ describe("Plete", function() {
4747
});
4848
});
4949

50+
it("renders the list items with an `aria-label` attribute", function() {
51+
const listItems = this.list.querySelectorAll("plete-item");
52+
53+
assert.isTrue(listItems.length > 0);
54+
listItems.forEach(function(item) {
55+
refute.isNull(item.getAttribute("aria-label"));
56+
});
57+
});
58+
59+
it("adds an `aria-activedescendant` attribute to the input", function() {
60+
const listItems = this.list.querySelectorAll("plete-item");
61+
62+
assert.isTrue(listItems.length > 0);
63+
refute.isNull(this.input);
64+
refute.isNull(this.input.getAttribute("aria-activedescendant"));
65+
});
66+
67+
it("renders the list items with an `id` attribute", function() {
68+
const listItems = this.list.querySelectorAll("plete-item");
69+
70+
assert.isTrue(listItems.length > 0);
71+
listItems.forEach(function(item) {
72+
refute.isNull(item.getAttribute("id"));
73+
});
74+
});
75+
5076
it("sets `aria-expanded` on the `plete` element to 'true'", function() {
5177
const plete = this.input.closest("plete");
5278

0 commit comments

Comments
 (0)