Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix a11y issues with inputs #1306

Merged
merged 4 commits into from
Sep 22, 2022
Merged
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
5 changes: 3 additions & 2 deletions addon/components/power-select-multiple/trigger.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
<li>
<input
type="search"
role="combobox"
class="ember-power-select-trigger-multiple-input"
aria-activedescendant={{if @select.isOpen @ariaActiveDescendant}}
aria-haspopup="listbox"
Expand All @@ -45,8 +44,10 @@
autocapitalize="off"
spellcheck={{false}}
id="ember-power-select-trigger-multiple-input-{{@select.uniqueId}}"
aria-labelledby={{@ariaLabelledBy}}
aria-label={{@ariaLabel}}
value={{@select.searchText}}
aria-controls={{@listboxId}}
aria-controls={{if @select.isOpen @listboxId}}
style={{this.triggerMultipleInputStyle}}
placeholder={{this.maybePlaceholder}}
disabled={{@select.disabled}}
Expand Down
20 changes: 18 additions & 2 deletions addon/components/power-select.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@
(component 'power-select/placeholder')
}}
@ariaActiveDescendant={{concat publicAPI.uniqueId "-" this.highlightedIndex}}
@ariaLabelledBy={{@ariaLabelledBy}}
@ariaLabel={{@ariaLabel}}
as |opt term|>
{{yield opt term}}
</Trigger>
Expand Down Expand Up @@ -109,6 +111,8 @@
@ariaActiveDescendant={{concat publicAPI.uniqueId "-" this.highlightedIndex}}
@selectedItemComponent={{ensure-safe-component @selectedItemComponent}}
@searchPlaceholder={{@searchPlaceholder}}
@ariaLabel={{@ariaLabel}}
@ariaLabelledBy={{@ariaLabelledBy}}
/>
{{/let}}
{{/if}}
Expand All @@ -120,7 +124,13 @@
(component 'power-select/search-message')
)
as |SearchMessage|}}
<SearchMessage @searchMessage={{this.searchMessage}} @select={{publicAPI}}/>
<SearchMessage
@searchMessage={{this.searchMessage}}
@select={{publicAPI}}
id={{listboxId}}
aria-label={{@ariaLabel}}
aria-labelledby={{@ariaLabelledBy}}
/>
{{/let}}
{{else if this.mustShowNoMessages}}
{{#let
Expand All @@ -130,7 +140,13 @@
(component 'power-select/no-matches-message')
)
as |NoMatchesMessage|}}
<NoMatchesMessage @noMatchesMessage={{this.noMatchesMessage}} @select={{publicAPI}} />
<NoMatchesMessage
@noMatchesMessage={{this.noMatchesMessage}}
@select={{publicAPI}}
id={{listboxId}}
aria-label={{@ariaLabel}}
aria-labelledby={{@ariaLabelledBy}}
/>
{{/let}}
{{else}}
{{#let
Expand Down
10 changes: 7 additions & 3 deletions addon/components/power-select/before-options.hbs
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
{{#if @searchEnabled}}
<div class="ember-power-select-search">
<input type="search" autocomplete="off"
autocorrect="off" autocapitalize="off"
spellcheck={{false}} role="combobox"
<input type="search"
autocomplete="off"
autocorrect="off"
autocapitalize="off"
spellcheck={{false}}
class="ember-power-select-search-input"
value={{@select.searchText}}
aria-activedescendant={{@ariaActiveDescendant}}
aria-controls={{@listboxId}}
aria-haspopup="listbox"
placeholder={{@searchPlaceholder}}
aria-label={{@ariaLabel}}
aria-labelledby={{@ariaLabelledBy}}
{{on "input" @onInput}}
{{on "focus" @onFocus}}
{{on "blur" @onBlur}}
Expand Down
2 changes: 1 addition & 1 deletion addon/components/power-select/search-message.hbs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<ul class="ember-power-select-options" role="listbox">
<ul class="ember-power-select-options" role="listbox" ...attributes>
<li class="ember-power-select-option ember-power-select-option--search-message" role="option">
{{@searchMessage}}
</li>
Expand Down
15 changes: 3 additions & 12 deletions tests/integration/components/power-select/a11y-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -652,7 +652,7 @@ module(
});

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

await render(hbs`
Expand All @@ -676,9 +676,7 @@ module(
'aria-controls',
document.querySelector('.ember-power-select-dropdown').id
);
assert
.dom('.ember-power-select-search-input')
.hasAttribute('role', 'combobox');

assert
.dom('.ember-power-select-search-input')
.hasAttribute('aria-haspopup', 'listbox');
Expand Down Expand Up @@ -815,7 +813,7 @@ module(
});

test('PowerSelectMultiple with search enabled has proper aria attributes', async function (assert) {
assert.expect(11);
assert.expect(10);
this.numbers = numbers;

await render(hbs`
Expand Down Expand Up @@ -852,13 +850,6 @@ module(

await clickTrigger();

assert
.dom('.ember-power-select-trigger-multiple-input')
.hasAttribute(
'role',
'combobox',
'Multi select search box has role combobox'
);
assert
.dom('.ember-power-select-trigger-multiple-input')
.hasAttribute(
Expand Down