Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/clear-suggestions.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ function clearSuggestions(state) {
state.selectedIndex = -1;
removeListElement(state);
state.input.removeAttribute("aria-controls");
state.input.removeAttribute("aria-activedescendant");
state.plete.setAttribute("aria-expanded", "false");
}
1 change: 1 addition & 0 deletions lib/highlight.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ function highlight(state, index) {
const item = state.list.querySelectorAll("plete-item")[index];
if (item) {
item.classList.add("highlight");
state.input.setAttribute("aria-activedescendant", item.id);
}
}
}
3 changes: 2 additions & 1 deletion lib/render.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ function render(state, data) {
addListElement(state, select);
const boundRenderItem = renderItem.bind(null, state);

data.map(boundRenderItem).forEach(function(item) {
data.map(boundRenderItem).forEach(function(item, idx) {
item.id = `plete-item-${idx}`;
state.list.appendChild(item);
});

Expand Down
28 changes: 27 additions & 1 deletion test/aria-support.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { assert } from "@sinonjs/referee-sinon";
import { assert, refute } from "@sinonjs/referee-sinon";
import { fireEvent, waitForElement } from "@testing-library/dom";
import { setupTest } from "./test-helper";

Expand Down Expand Up @@ -47,6 +47,32 @@ describe("Plete", function() {
});
});

it("adds an `aria-activedescendant` attribute to the input", function() {
const listItems = this.list.querySelectorAll("plete-item");

assert.isTrue(listItems.length > 0);
refute.isNull(this.input);
refute.isNull(this.input.getAttribute("aria-activedescendant"));
});

it("renders the list items with an `id` attribute", function() {
const listItems = this.list.querySelectorAll("plete-item");

assert.isTrue(listItems.length > 0);
listItems.forEach(function(item) {
refute.isNull(item.getAttribute("id"));
});
});

it("`aria-activedescendant` attribute corresponds to an `id` attribute of another DOM node", function() {
const listItems = this.list.querySelectorAll("plete-item");

assert.isTrue(listItems.length > 0);
refute.isNull(this.input);
const activeDescendant = this.input.getAttribute("aria-activedescendant");
refute.isNull(document.getElementById(activeDescendant));
});

it("sets `aria-expanded` on the `plete` element to 'true'", function() {
const plete = this.input.closest("plete");

Expand Down