Skip to content

Commit

Permalink
fix: add aria-activedescendant only when there is one (#1137)
Browse files Browse the repository at this point in the history
  • Loading branch information
sagalbot authored Mar 26, 2020
1 parent 87a7b18 commit 1130632
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/components/Select.vue
Original file line number Diff line number Diff line change
Expand Up @@ -1039,11 +1039,13 @@
'aria-autocomplete': 'list',
'aria-labelledby': `vs${this.uid}__combobox`,
'aria-controls': `vs${this.uid}__listbox`,
'aria-activedescendant': this.typeAheadPointer > -1 ? `vs${this.uid}__option-${this.typeAheadPointer}` : '',
'ref': 'search',
'type': 'search',
'autocomplete': this.autocomplete,
'value': this.search,
...(this.dropdownOpen && this.filteredOptions[this.typeAheadPointer] ? {
'aria-activedescendant': `vs${this.uid}__option-${this.typeAheadPointer}`
} : {}),
},
events: {
'compositionstart': () => this.isComposing = true,
Expand Down
35 changes: 35 additions & 0 deletions tests/unit/Accessibility.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { mountDefault } from "../helpers";

describe("Search Slot Scope", () => {
/**
* @see https://www.w3.org/WAI/PF/aria/states_and_properties#aria-activedescendant
*/
describe("aria-activedescendant", () => {
it("adds the active descendant attribute only when the dropdown is open and there is a typeAheadPointer value", async () => {
const Select = mountDefault();

expect(
Select.vm.scope.search.attributes["aria-activedescendant"]
).toEqual(undefined);

Select.vm.open = true;
await Select.vm.$nextTick();

expect(
Select.vm.scope.search.attributes["aria-activedescendant"]
).toEqual(undefined);
});

it("adds the active descendant attribute when there's a typeahead value and an open dropdown", async () => {
const Select = mountDefault();

Select.vm.open = true;
Select.vm.typeAheadPointer = 1;
await Select.vm.$nextTick();

expect(
Select.vm.scope.search.attributes["aria-activedescendant"]
).toEqual(`vs${Select.vm.uid}__option-1`);
});
});
});

0 comments on commit 1130632

Please sign in to comment.