Skip to content

Commit

Permalink
fix(core): rely only on [tuiOption] html attribute for search options
Browse files Browse the repository at this point in the history
  • Loading branch information
splincode committed Sep 11, 2024
1 parent caab33f commit e692e9b
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions projects/core/components/data-list/data-list.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,25 @@ import {
ChangeDetectionStrategy,
Component,
ContentChildren,
DestroyRef,
forwardRef,
inject,
Input,
NgZone,
signal,
ViewEncapsulation,
} from '@angular/core';
import {toSignal} from '@angular/core/rxjs-interop';
import {EMPTY_QUERY} from '@taiga-ui/cdk/constants';
import {tuiTakeUntilDestroyed, tuiZonefreeScheduler} from '@taiga-ui/cdk/observables';
import {tuiInjectElement} from '@taiga-ui/cdk/utils/dom';
import {tuiIsNativeFocusedIn, tuiMoveFocus} from '@taiga-ui/cdk/utils/focus';
import {tuiIsPresent} from '@taiga-ui/cdk/utils/miscellaneous';
import {TUI_NOTHING_FOUND_MESSAGE} from '@taiga-ui/core/tokens';
import type {TuiSizeL, TuiSizeS} from '@taiga-ui/core/types';
import type {PolymorpheusContent} from '@taiga-ui/polymorpheus';
import {PolymorpheusOutlet} from '@taiga-ui/polymorpheus';
import {timer} from 'rxjs';

import type {TuiDataListAccessor} from './data-list.tokens';
import {TUI_DATA_LIST_HOST, tuiAsDataListAccessor} from './data-list.tokens';
Expand Down Expand Up @@ -61,6 +65,8 @@ export class TuiDataListComponent<T>
private readonly options: QueryList<TuiOption<T>> = EMPTY_QUERY;

private origin?: HTMLElement;
private readonly ngZone = inject(NgZone);
private readonly destroyRef = inject(DestroyRef);
private readonly el = tuiInjectElement();

protected readonly fallback = toSignal(inject(TUI_NOTHING_FOUND_MESSAGE));
Expand All @@ -84,9 +90,11 @@ export class TuiDataListComponent<T>
}
}

// TODO: Refactor to :has after Safari support bumped to 15
public ngAfterContentChecked(): void {
// TODO: Refactor to :has after Safari support bumped to 15
this.empty.set(!this.options.length);
timer(0, tuiZonefreeScheduler(this.ngZone))
.pipe(tuiTakeUntilDestroyed(this.destroyRef))
.subscribe(() => this.empty.set(!this.el.querySelector('[tuiOption]')));
}

public getOptions(includeDisabled = false): readonly T[] {
Expand Down

0 comments on commit e692e9b

Please sign in to comment.