Skip to content

Commit

Permalink
Fix a11y error for single select with search field position trigger (#…
Browse files Browse the repository at this point in the history
…1866)

* Fix a11y error for single select with search field position trigger

* Fix lint

* Add check for searchEnabled
  • Loading branch information
mkszepp authored Dec 27, 2024
1 parent 5bf2ea0 commit f9e0ab0
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 6 deletions.
2 changes: 1 addition & 1 deletion ember-power-select/src/components/power-select.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
role={{or @triggerRole "combobox"}}
title={{@title}}
id={{this.triggerId}}
tabindex={{and (not @disabled) (or @tabindex "0")}}
tabindex={{and (not @disabled) (or this.tabindex "0")}}
...attributes
>
{{#let
Expand Down
14 changes: 13 additions & 1 deletion ember-power-select/src/components/power-select.ts
Original file line number Diff line number Diff line change
Expand Up @@ -370,12 +370,24 @@ export default class PowerSelectComponent extends Component<PowerSelectSignature
return '';
}

get searchFieldPosition(): string {
get searchFieldPosition(): TSearchFieldPosition {
return this.args.searchFieldPosition === undefined
? 'before-options'
: this.args.searchFieldPosition;
}

get tabindex(): string | number {
if (
this.args.searchEnabled &&
this.args.tabindex === undefined &&
this.searchFieldPosition === 'trigger'
) {
return '-1';
}

return this.args.tabindex || '0';
}

// Actions
@action
handleOpen(_select: Select, e: Event): boolean | void {
Expand Down
6 changes: 3 additions & 3 deletions ember-power-select/src/components/power-select/input.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
class="ember-power-select-search-input-field"
value={{@select.searchText}}
role={{or @role "combobox"}}
aria-activedescendant={{@ariaActiveDescendant}}
aria-controls={{@listboxId}}
aria-owns={{@listboxId}}
aria-activedescendant={{if @select.isOpen @ariaActiveDescendant}}
aria-controls={{if @select.isOpen @listboxId}}
aria-owns={{if @select.isOpen @listboxId}}
aria-autocomplete="list"
aria-haspopup="listbox"
aria-expanded={{if @select.isOpen "true" "false"}}
Expand Down
4 changes: 3 additions & 1 deletion test-app/app/components/custom-trigger-with-search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ export interface CustomTriggerWithSearchSignature {
export default class CustomGroupComponent extends Component<CustomTriggerWithSearchSignature> {
@action
onSearch(evt: Event) {
this.args.select.actions.search((evt.target as HTMLInputElement).value ?? '');
this.args.select.actions.search(
(evt.target as HTMLInputElement).value ?? '',
);
}
}

0 comments on commit f9e0ab0

Please sign in to comment.