Add aria-activedescendant attribute only when dropdown is active

This commit is contained in:
Vladimir Kolmakov 2017-08-16 11:28:50 -05:00
parent 0f81a03e19
commit 7aee340a8b

View file

@ -797,6 +797,10 @@ class Choices {
this.containerOuter.setAttribute('aria-expanded', 'false');
this.dropdown.classList.remove(this.config.classNames.activeState);
this.dropdown.setAttribute('aria-expanded', 'false');
// IE11 ignores aria-label and blocks virtual keyboard
// if aria-activedescendant is set without a dropdown
this.input.removeAttribute('aria-activedescendant');
this.containerOuter.removeAttribute('aria-activedescendant');
if (isFlipped) {
this.containerOuter.classList.remove(this.config.classNames.flippedState);
@ -2198,7 +2202,16 @@ class Choices {
// Highlight given option, and set accessiblity attributes
passedEl.classList.add(this.config.classNames.highlightedState);
passedEl.setAttribute('aria-selected', 'true');
this.containerOuter.setAttribute('aria-activedescendant', passedEl.id);
const hasActiveDropdown = this.dropdown.classList.contains(
this.config.classNames.activeState
);
if (hasActiveDropdown) {
// IE11 ignores aria-label and blocks virtual keyboard
// if aria-activedescendant is set without a dropdown
this.input.setAttribute('aria-activedescendant', passedEl.id);
this.containerOuter.setAttribute('aria-activedescendant', passedEl.id);
}
}
}