Skip to content

Commit f19cc50

Browse files
ARIA activedescendant, label
1 parent de63b80 commit f19cc50

File tree

4 files changed

+31
-2
lines changed

4 files changed

+31
-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.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("adds an `aria-activedescendant` attribute to the input", function() {
51+
const listItems = this.list.querySelectorAll("plete-item");
52+
53+
assert.isTrue(listItems.length > 0);
54+
refute.isNull(this.input);
55+
refute.isNull(this.input.getAttribute("aria-activedescendant"));
56+
});
57+
58+
it("renders the list items with an `id` attribute", function() {
59+
const listItems = this.list.querySelectorAll("plete-item");
60+
61+
assert.isTrue(listItems.length > 0);
62+
listItems.forEach(function(item) {
63+
refute.isNull(item.getAttribute("id"));
64+
});
65+
});
66+
67+
it("`aria-activedescendant` attribute corresponds to an `id` attribute of another DOM node", function() {
68+
const listItems = this.list.querySelectorAll("plete-item");
69+
70+
assert.isTrue(listItems.length > 0);
71+
refute.isNull(this.input);
72+
const activeDescendant = this.input.getAttribute("aria-activedescendant");
73+
refute.isNull(document.getElementById(activeDescendant));
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)