Skip to content

Commit ac29f10

Browse files
mydeaFrancesco Novy
andauthored
Fix a11y issues with inputs (#1306)
* Pass aria-labelledby & aria-label through to multi select input Also remove `type="listbox"` from search input, as that is redundant and axe complains about it. * Only Add aria-controls to multi-select trigger if select is open Otherwise, axe complains that the aria-controls element it refers to doesn't exist. * Add aria-label & aria-labelled-by to single select search input Otherwise, the input has no label. This also removes the role="combobox" from the input, as that is redundant for input type="search" and axe also complains about it. * Add id, aria-label & aria-labelledby to all listboxes Co-authored-by: Francesco Novy <francesco@cropster.com>
1 parent 8ce6f31 commit ac29f10

File tree

5 files changed

+32
-20
lines changed

5 files changed

+32
-20
lines changed

addon/components/power-select-multiple/trigger.hbs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
<li>
3636
<input
3737
type="search"
38-
role="combobox"
3938
class="ember-power-select-trigger-multiple-input"
4039
aria-activedescendant={{if @select.isOpen @ariaActiveDescendant}}
4140
aria-haspopup="listbox"
@@ -45,8 +44,10 @@
4544
autocapitalize="off"
4645
spellcheck={{false}}
4746
id="ember-power-select-trigger-multiple-input-{{@select.uniqueId}}"
47+
aria-labelledby={{@ariaLabelledBy}}
48+
aria-label={{@ariaLabel}}
4849
value={{@select.searchText}}
49-
aria-controls={{@listboxId}}
50+
aria-controls={{if @select.isOpen @listboxId}}
5051
style={{this.triggerMultipleInputStyle}}
5152
placeholder={{this.maybePlaceholder}}
5253
disabled={{@select.disabled}}

addon/components/power-select.hbs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@
8181
(component 'power-select/placeholder')
8282
}}
8383
@ariaActiveDescendant={{concat publicAPI.uniqueId "-" this.highlightedIndex}}
84+
@ariaLabelledBy={{@ariaLabelledBy}}
85+
@ariaLabel={{@ariaLabel}}
8486
as |opt term|>
8587
{{yield opt term}}
8688
</Trigger>
@@ -109,6 +111,8 @@
109111
@ariaActiveDescendant={{concat publicAPI.uniqueId "-" this.highlightedIndex}}
110112
@selectedItemComponent={{ensure-safe-component @selectedItemComponent}}
111113
@searchPlaceholder={{@searchPlaceholder}}
114+
@ariaLabel={{@ariaLabel}}
115+
@ariaLabelledBy={{@ariaLabelledBy}}
112116
/>
113117
{{/let}}
114118
{{/if}}
@@ -120,7 +124,13 @@
120124
(component 'power-select/search-message')
121125
)
122126
as |SearchMessage|}}
123-
<SearchMessage @searchMessage={{this.searchMessage}} @select={{publicAPI}}/>
127+
<SearchMessage
128+
@searchMessage={{this.searchMessage}}
129+
@select={{publicAPI}}
130+
id={{listboxId}}
131+
aria-label={{@ariaLabel}}
132+
aria-labelledby={{@ariaLabelledBy}}
133+
/>
124134
{{/let}}
125135
{{else if this.mustShowNoMessages}}
126136
{{#let
@@ -130,7 +140,13 @@
130140
(component 'power-select/no-matches-message')
131141
)
132142
as |NoMatchesMessage|}}
133-
<NoMatchesMessage @noMatchesMessage={{this.noMatchesMessage}} @select={{publicAPI}} />
143+
<NoMatchesMessage
144+
@noMatchesMessage={{this.noMatchesMessage}}
145+
@select={{publicAPI}}
146+
id={{listboxId}}
147+
aria-label={{@ariaLabel}}
148+
aria-labelledby={{@ariaLabelledBy}}
149+
/>
134150
{{/let}}
135151
{{else}}
136152
{{#let

addon/components/power-select/before-options.hbs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
{{#if @searchEnabled}}
22
<div class="ember-power-select-search">
3-
<input type="search" autocomplete="off"
4-
autocorrect="off" autocapitalize="off"
5-
spellcheck={{false}} role="combobox"
3+
<input type="search"
4+
autocomplete="off"
5+
autocorrect="off"
6+
autocapitalize="off"
7+
spellcheck={{false}}
68
class="ember-power-select-search-input"
79
value={{@select.searchText}}
810
aria-activedescendant={{@ariaActiveDescendant}}
911
aria-controls={{@listboxId}}
1012
aria-haspopup="listbox"
1113
placeholder={{@searchPlaceholder}}
14+
aria-label={{@ariaLabel}}
15+
aria-labelledby={{@ariaLabelledBy}}
1216
{{on "input" @onInput}}
1317
{{on "focus" @onFocus}}
1418
{{on "blur" @onBlur}}

addon/components/power-select/search-message.hbs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<ul class="ember-power-select-options" role="listbox">
1+
<ul class="ember-power-select-options" role="listbox" ...attributes>
22
<li class="ember-power-select-option ember-power-select-option--search-message" role="option">
33
{{@searchMessage}}
44
</li>

tests/integration/components/power-select/a11y-test.js

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -652,7 +652,7 @@ module(
652652
});
653653

654654
test('Dropdown with search enabled has proper aria attributes to associate search box with the options', async function (assert) {
655-
assert.expect(5);
655+
assert.expect(4);
656656
this.numbers = numbers;
657657

658658
await render(hbs`
@@ -676,9 +676,7 @@ module(
676676
'aria-controls',
677677
document.querySelector('.ember-power-select-dropdown').id
678678
);
679-
assert
680-
.dom('.ember-power-select-search-input')
681-
.hasAttribute('role', 'combobox');
679+
682680
assert
683681
.dom('.ember-power-select-search-input')
684682
.hasAttribute('aria-haspopup', 'listbox');
@@ -815,7 +813,7 @@ module(
815813
});
816814

817815
test('PowerSelectMultiple with search enabled has proper aria attributes', async function (assert) {
818-
assert.expect(11);
816+
assert.expect(10);
819817
this.numbers = numbers;
820818

821819
await render(hbs`
@@ -852,13 +850,6 @@ module(
852850

853851
await clickTrigger();
854852

855-
assert
856-
.dom('.ember-power-select-trigger-multiple-input')
857-
.hasAttribute(
858-
'role',
859-
'combobox',
860-
'Multi select search box has role combobox'
861-
);
862853
assert
863854
.dom('.ember-power-select-trigger-multiple-input')
864855
.hasAttribute(

0 commit comments

Comments
 (0)