From e711ab72e5da5d178f43b1db37b3df735f4cf64d Mon Sep 17 00:00:00 2001 From: shiv9604 Date: Sat, 23 Nov 2024 02:21:06 +0530 Subject: [PATCH] feat(core): resolve pr comments 3 --- .../dropdown-position-sided.directive.ts | 21 ++++--------------- .../dropdown/dropdown-position.directive.ts | 5 +++-- .../utils/miscellaneous/emit-when-changed.ts | 15 ------------- projects/core/utils/miscellaneous/index.ts | 1 - 4 files changed, 7 insertions(+), 35 deletions(-) delete mode 100644 projects/core/utils/miscellaneous/emit-when-changed.ts diff --git a/projects/core/directives/dropdown/dropdown-position-sided.directive.ts b/projects/core/directives/dropdown/dropdown-position-sided.directive.ts index 13ae01f70a2bf..39ba8eb0aab6e 100644 --- a/projects/core/directives/dropdown/dropdown-position-sided.directive.ts +++ b/projects/core/directives/dropdown/dropdown-position-sided.directive.ts @@ -1,9 +1,8 @@ -import {Directive, EventEmitter, inject, Input, Output} from '@angular/core'; +import {Directive, inject, Input} from '@angular/core'; import {EMPTY_CLIENT_RECT} from '@taiga-ui/cdk/constants'; import {tuiAsPositionAccessor, TuiPositionAccessor} from '@taiga-ui/core/classes'; import {TUI_VIEWPORT} from '@taiga-ui/core/tokens'; -import type {TuiPoint, TuiVerticalDirection} from '@taiga-ui/core/types'; -import {tuiEmitWhenChanged} from '@taiga-ui/core/utils'; +import type {TuiPoint} from '@taiga-ui/core/types'; import {TUI_DROPDOWN_OPTIONS} from './dropdown-options.directive'; import {TuiDropdownPosition} from './dropdown-position.directive'; @@ -11,14 +10,13 @@ import {TuiDropdownPosition} from './dropdown-position.directive'; @Directive({ standalone: true, selector: '[tuiDropdownSided]', - providers: [tuiAsPositionAccessor(TuiDropdownPositionSided)], + providers: [TuiDropdownPosition, tuiAsPositionAccessor(TuiDropdownPositionSided)], }) export class TuiDropdownPositionSided extends TuiPositionAccessor { private readonly options = inject(TUI_DROPDOWN_OPTIONS); private readonly viewport = inject(TUI_VIEWPORT); private readonly vertical = inject(TuiDropdownPosition); private previous = this.options.direction || 'bottom'; - private lastDirection!: TuiVerticalDirection; @Input() public tuiDropdownSided: boolean | string = ''; @@ -26,9 +24,6 @@ export class TuiDropdownPositionSided extends TuiPositionAccessor { @Input() public tuiDropdownSidedOffset = 4; - @Output('tuiDropdownDirectionChange') - public readonly directionChange = new EventEmitter(); - public readonly type = 'dropdown'; public getPosition(rect: DOMRect): TuiPoint { @@ -61,7 +56,7 @@ export class TuiDropdownPositionSided extends TuiPositionAccessor { (available[this.previous] > minHeight && direction) || this.previous === better ) { - this.vertical.emitDirection(better); + this.vertical.emitDirection(this.previous); return [position[this.previous], left]; } @@ -71,12 +66,4 @@ export class TuiDropdownPositionSided extends TuiPositionAccessor { return [position[better], left]; } - - public emitDirection(direction: TuiVerticalDirection): void { - this.lastDirection = tuiEmitWhenChanged( - direction, - this.lastDirection, - this.directionChange, - ); - } } diff --git a/projects/core/directives/dropdown/dropdown-position.directive.ts b/projects/core/directives/dropdown/dropdown-position.directive.ts index 4ab4beecace9c..f6f42ef8a3eec 100644 --- a/projects/core/directives/dropdown/dropdown-position.directive.ts +++ b/projects/core/directives/dropdown/dropdown-position.directive.ts @@ -71,16 +71,17 @@ export class TuiDropdownPosition extends TuiPositionAccessor { const better: TuiVerticalDirection = available.top > available.bottom ? 'top' : 'bottom'; - this.emitDirection(better); - if ( (available[previous] > minHeight && direction) || available[previous] > height ) { + this.emitDirection(previous); + return [position[previous], position[align]]; } this.previous = better; + this.emitDirection(better); return [position[better], position[align]]; } diff --git a/projects/core/utils/miscellaneous/emit-when-changed.ts b/projects/core/utils/miscellaneous/emit-when-changed.ts deleted file mode 100644 index 67ca5192fbc32..0000000000000 --- a/projects/core/utils/miscellaneous/emit-when-changed.ts +++ /dev/null @@ -1,15 +0,0 @@ -import type {EventEmitter} from '@angular/core'; - -export function tuiEmitWhenChanged( - newValue: T, - lastEmittedValue: T, - emitter: EventEmitter, -): T { - if (lastEmittedValue !== newValue) { - emitter.emit(newValue); - - return newValue; - } - - return lastEmittedValue; -} diff --git a/projects/core/utils/miscellaneous/index.ts b/projects/core/utils/miscellaneous/index.ts index 95725b7c16253..2904850721867 100644 --- a/projects/core/utils/miscellaneous/index.ts +++ b/projects/core/utils/miscellaneous/index.ts @@ -1,4 +1,3 @@ -export * from './emit-when-changed'; export * from './is-editing-key'; export * from './is-obscured'; export * from './override-options';