Skip to content

Commit

Permalink
fix(combobox): enable screen readers to announce "no results" properly (
Browse files Browse the repository at this point in the history
#1316)

CDE-1515

Co-authored-by: Kevin Buhmann <[email protected]>
(cherry picked from commit a158ac7)
  • Loading branch information
mivaylo authored and github-actions[bot] committed Apr 3, 2024
1 parent 6ca101e commit bb28c18
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
2 changes: 2 additions & 0 deletions projects/angular/clarity.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -2869,6 +2869,8 @@ export class ClrOptions<T> implements AfterViewInit, LoadingListener, OnDestroy
// (undocumented)
ngOnDestroy(): void;
// (undocumented)
get noResultsElementId(): string;
// (undocumented)
optionSelectionService: OptionSelectionService<T>;
// (undocumented)
optionsId: string;
Expand Down
2 changes: 1 addition & 1 deletion projects/angular/src/forms/combobox/combobox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ export class ClrCombobox<T>

getActiveDescendant() {
const model = this.focusHandler.pseudoFocus.model;
return model ? model.id : null;
return model ? model.id : this.options?.noResultsElementId;
}

setDisabledState(): void {
Expand Down
6 changes: 5 additions & 1 deletion projects/angular/src/forms/combobox/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ let nbOptionsComponents = 0;
</div>
<!-- Rendered if data set is empty -->
<div *ngIf="emptyOptions">
<div *ngIf="emptyOptions" [id]="noResultsElementId" role="option">
<span class="clr-combobox-options-empty-text">
{{ commonStrings.keys.comboboxNoResults }}
</span>
Expand Down Expand Up @@ -104,6 +104,10 @@ export class ClrOptions<T> implements AfterViewInit, LoadingListener, OnDestroy
return !this.optionSelectionService.loading && this.items.length === 0;
}

get noResultsElementId() {
return `${this.optionsId}-no-results`;
}

ngAfterViewInit() {
this.focusHandler.listbox = this.el.nativeElement;

Expand Down

0 comments on commit bb28c18

Please sign in to comment.