From f8ea2f2d41351dae33362acee7dd12e99767eea2 Mon Sep 17 00:00:00 2001 From: "Shivprasad Kounsalye (Remote Angular Dev)" Date: Fri, 13 Dec 2024 13:30:23 +0530 Subject: [PATCH] fix(core): emit tuiDropdownOpenChange on distinct values (#9962) --- .../dropdown/dropdown-open-legacy.directive.ts | 13 ++++++++++--- .../legacy-dropdown-open-monitor.ts | 2 +- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/projects/core/directives/dropdown/dropdown-open-legacy.directive.ts b/projects/core/directives/dropdown/dropdown-open-legacy.directive.ts index ded45fa8ffd5..1c1c4a98dc16 100644 --- a/projects/core/directives/dropdown/dropdown-open-legacy.directive.ts +++ b/projects/core/directives/dropdown/dropdown-open-legacy.directive.ts @@ -1,5 +1,5 @@ import {Directive, Input, Output} from '@angular/core'; -import {BehaviorSubject} from 'rxjs'; +import {distinctUntilChanged, Subject} from 'rxjs'; /** * @deprecated TODO: remove in v.5 when legacy controls are dropped @@ -10,11 +10,18 @@ import {BehaviorSubject} from 'rxjs'; '[tuiDropdownOpen]:not([tuiDropdown]),[tuiDropdownOpenChange]:not([tuiDropdown])', }) export class TuiDropdownOpenLegacy { + private readonly openStateSub = new Subject(); + @Output() - public readonly tuiDropdownOpenChange = new BehaviorSubject(false); + public readonly tuiDropdownOpenChange = + this.openStateSub.pipe(distinctUntilChanged()); @Input() public set tuiDropdownOpen(open: boolean) { - this.tuiDropdownOpenChange.next(open); + this.emitOpenChange(open); + } + + public emitOpenChange(open: boolean): void { + this.openStateSub.next(open); } } diff --git a/projects/legacy/directives/legacy-dropdown-open-monitor/legacy-dropdown-open-monitor.ts b/projects/legacy/directives/legacy-dropdown-open-monitor/legacy-dropdown-open-monitor.ts index 9fd6cb8fcf88..e0d027a48492 100644 --- a/projects/legacy/directives/legacy-dropdown-open-monitor/legacy-dropdown-open-monitor.ts +++ b/projects/legacy/directives/legacy-dropdown-open-monitor/legacy-dropdown-open-monitor.ts @@ -34,6 +34,6 @@ export class TuiLegacyDropdownOpenMonitorDirective implements AfterViewInit { this.host.driver .pipe(distinctUntilChanged(), takeUntilDestroyed(this.destroyRef)) - .subscribe((open) => this.external?.tuiDropdownOpenChange.next(open)); + .subscribe((open) => this.external?.emitOpenChange(open)); } }