From e9eca035f41679c92dbcbe5693abe0609cb09927 Mon Sep 17 00:00:00 2001 From: fengtianze Date: Mon, 5 Aug 2024 13:37:49 +0800 Subject: [PATCH] fix: autocomplete empty suggestion --- src/autocomplete/autocomplete.component.ts | 5 +++-- stories/autocomplete/disabled.component.ts | 16 +++++++--------- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/autocomplete/autocomplete.component.ts b/src/autocomplete/autocomplete.component.ts index 8ea4af1fa..52dbf78e8 100644 --- a/src/autocomplete/autocomplete.component.ts +++ b/src/autocomplete/autocomplete.component.ts @@ -64,16 +64,17 @@ export class AutocompleteComponent implements AfterContentInit { ngAfterContentInit() { this.visibles$ = this.suggestions.changes.pipe( + startWith(this.suggestions), switchMap((suggestions: QueryList) => suggestions.length > 0 ? combineLatest(suggestions.map(suggestion => suggestion.visible$)) : of([] as boolean[]), ), - debounceTime(0), - startWith(this.suggestions.map(suggestion => suggestion.visible)), publishRef(), ); + this.hasVisibleSuggestion$ = this.visibles$.pipe( + debounceTime(0), map(visible => visible.some(Boolean)), withLatestFrom(this.directive$$), map(([hasVisibleSuggestion, directive]) => { diff --git a/stories/autocomplete/disabled.component.ts b/stories/autocomplete/disabled.component.ts index 3ce71d325..221814cba 100644 --- a/stories/autocomplete/disabled.component.ts +++ b/stories/autocomplete/disabled.component.ts @@ -7,15 +7,13 @@ import { ChangeDetectionStrategy, Component } from '@angular/core';

-
- -
+ apple banana