Skip to content

Commit

Permalink
feat(core): resolve pr comments 3
Browse files Browse the repository at this point in the history
  • Loading branch information
shiv9604 committed Nov 22, 2024
1 parent 632d76f commit e711ab7
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 35 deletions.
Original file line number Diff line number Diff line change
@@ -1,34 +1,29 @@
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';

@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 = '';

@Input()
public tuiDropdownSidedOffset = 4;

@Output('tuiDropdownDirectionChange')
public readonly directionChange = new EventEmitter<TuiVerticalDirection>();

public readonly type = 'dropdown';

public getPosition(rect: DOMRect): TuiPoint {
Expand Down Expand Up @@ -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];
}
Expand All @@ -71,12 +66,4 @@ export class TuiDropdownPositionSided extends TuiPositionAccessor {

return [position[better], left];
}

public emitDirection(direction: TuiVerticalDirection): void {
this.lastDirection = tuiEmitWhenChanged<TuiVerticalDirection>(
direction,
this.lastDirection,
this.directionChange,
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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]];
}
Expand Down
15 changes: 0 additions & 15 deletions projects/core/utils/miscellaneous/emit-when-changed.ts

This file was deleted.

1 change: 0 additions & 1 deletion projects/core/utils/miscellaneous/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
export * from './emit-when-changed';
export * from './is-editing-key';
export * from './is-obscured';
export * from './override-options';
Expand Down

0 comments on commit e711ab7

Please sign in to comment.