Skip to content

Commit

Permalink
Merge branch 'v3.x' into dropdown-context-ios
Browse files Browse the repository at this point in the history
  • Loading branch information
MillerSvt authored Feb 12, 2024
2 parents e882f9f + 120eb82 commit 55b081b
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 19 deletions.
31 changes: 20 additions & 11 deletions projects/core/components/expand/expand.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,14 @@ import {
HostListener,
Inject,
Input,
Self,
TemplateRef,
ViewChild,
} from '@angular/core';
import {TUI_PARENT_ANIMATION, TuiValuesOf} from '@taiga-ui/cdk';
import {TUI_PARENT_ANIMATION, TuiDestroyService, TuiValuesOf} from '@taiga-ui/cdk';
import {TUI_EXPAND_LOADED} from '@taiga-ui/core/constants';
import {Observable, timer} from 'rxjs';
import {takeUntil} from 'rxjs/operators';

import {TuiExpandContentDirective} from './expand-content.directive';

Expand All @@ -31,6 +34,7 @@ const LOADER_HEIGHT = 48;
templateUrl: './expand.template.html',
styleUrls: ['./expand.style.less'],
changeDetection: ChangeDetectionStrategy.OnPush,
providers: [TuiDestroyService],
animations: [TUI_PARENT_ANIMATION],
})
export class TuiExpandComponent {
Expand Down Expand Up @@ -68,7 +72,10 @@ export class TuiExpandComponent {
@HostBinding('attr.aria-expanded')
expanded: boolean | null = null;

constructor(@Inject(ChangeDetectorRef) private readonly cdr: ChangeDetectorRef) {}
constructor(
@Inject(ChangeDetectorRef) private readonly cdr: ChangeDetectorRef,
@Self() @Inject(TuiDestroyService) private readonly destroy$: Observable<void>,
) {}

@HostBinding('class._overflow')
get overflow(): boolean {
Expand Down Expand Up @@ -129,14 +136,16 @@ export class TuiExpandComponent {
private retrigger(state: TuiValuesOf<typeof State>): void {
this.state = State.Prepared;

// We need delay to re-trigger CSS height transition from the correct number
setTimeout(() => {
if (this.state !== State.Prepared) {
return;
}

this.state = state;
this.cdr.markForCheck();
});
timer(0)
.pipe(takeUntil(this.destroy$))
.subscribe(() => {
// We need delay to re-trigger CSS height transition from the correct number
if (this.state !== State.Prepared) {
return;
}

this.state = state;
this.cdr.markForCheck();
});
}
}
8 changes: 6 additions & 2 deletions projects/core/directives/dropdown/dropdown.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ export class TuiDropdownComponent {
private update(top: number, left: number): void {
const {style} = this.el.nativeElement;
const {right} = this.el.nativeElement.getBoundingClientRect();
const {maxHeight, offset} = this.options;
const {maxHeight, minHeight, offset} = this.options;
const {innerHeight} = this.win;
const clientRect = this.el.nativeElement.offsetParent?.getBoundingClientRect();
const {position} = this.directive;
Expand All @@ -116,10 +116,14 @@ export class TuiDropdownComponent {
? rect.top - 2 * offset
: offsetY + innerHeight - top - offset;

const sided = right <= rect.left || left >= rect.right;

style.position = position;
style.top = tuiPx(Math.max(top, offsetY + offset));
style.left = tuiPx(left);
style.maxHeight = tuiPx(Math.min(maxHeight, available));
style.maxHeight = sided
? `min(100%, ${maxHeight}px)`
: tuiPx(Math.min(maxHeight, Math.max(available, minHeight)));
style.width = '';
style.minWidth = '';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,7 @@
</div>

<button
iconLeft="tuiIconEye"
size="m"
tuiIconButton
tuiSwipeAction
></button>
<button
*ngIf="editButton"
iconLeft="tuiIconEdit3"
size="m"
tuiIconButton
Expand All @@ -44,3 +39,11 @@
/>
Share button
</label>
<label>
<input
tuiCheckbox
type="checkbox"
[(ngModel)]="editButton"
/>
Edit button
</label>
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ button[tuiSwipeAction] {
label {
display: flex;
align-items: center;
margin-top: 0.5rem;
}

input[type='checkbox'] {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ import {encapsulation} from '@demo/emulate/encapsulation';
})
export class TuiSwipeActionExample4 {
shareButton = false;
editButton = true;
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@
align-items: center;
transform-style: preserve-3d;

&:empty {
display: none;
}

::ng-deep & > * {
.loop(6);
}
Expand Down

0 comments on commit 55b081b

Please sign in to comment.