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 error for single select with search field position trigger #1866

Merged
merged 3 commits into from
Dec 27, 2024
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
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 ?? '',
);
}
}
Loading