Skip to content

Commit

Permalink
fix(core): Dialog fix scrollbar width issues (#5488)
Browse files Browse the repository at this point in the history
  • Loading branch information
waterplea authored Oct 2, 2023
1 parent ded734c commit 75358a8
Show file tree
Hide file tree
Showing 40 changed files with 462 additions and 60 deletions.
3 changes: 2 additions & 1 deletion .cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
"letraset",
"aldus",
"hangoff",
"tcrm"
"tcrm",
"scrollbars"
],
"ignoreRegExpList": ["\\(https?://.*?\\)", "\\/{1}.+\\/{1}", "\\%2F.+", "\\%2C.+", "\\ɵ.+", "\\ыва.+"],
"overrides": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ import {
} from '@angular/core';
import {
TUI_IS_IOS,
TUI_SCROLL_REF,
TuiContextWithImplicit,
TuiDestroyService,
TuiHandler,
tuiPx,
tuiScrollFrom,
tuiZonefree,
} from '@taiga-ui/cdk';
import {TUI_SCROLL_REF} from '@taiga-ui/core';
import {PolymorpheusContent} from '@tinkoff/ng-polymorpheus';
import {Observable} from 'rxjs';
import {distinctUntilChanged, filter, map, startWith, takeUntil} from 'rxjs/operators';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import {ElementRef, Inject, Injectable} from '@angular/core';
import {tuiScrollFrom, tuiTypedFromEvent} from '@taiga-ui/cdk';
import {TUI_SCROLL_REF} from '@taiga-ui/core';
import {TUI_SCROLL_REF, tuiScrollFrom, tuiTypedFromEvent} from '@taiga-ui/cdk';
import {EMPTY, Observable} from 'rxjs';
import {
distinctUntilChanged,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import {
ALWAYS_FALSE_HANDLER,
ALWAYS_TRUE_HANDLER,
TUI_IS_IOS,
TUI_SCROLL_REF,
tuiTypedFromEvent,
tuiZonefree,
} from '@taiga-ui/cdk';
import {TUI_SCROLL_REF} from '@taiga-ui/core';
import {merge, Observable} from 'rxjs';
import {map, share} from 'rxjs/operators';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import {Directive, ElementRef, Inject, Self} from '@angular/core';
import {TuiDestroyService} from '@taiga-ui/cdk';
import {TUI_SCROLL_REF} from '@taiga-ui/core';
import {TUI_SCROLL_REF, TuiDestroyService} from '@taiga-ui/cdk';
import {Observable} from 'rxjs';
import {
distinctUntilChanged,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import {ElementRef, Inject, Injectable, NgZone, Self} from '@angular/core';
import {
SCROLL_REF_SELECTOR,
TUI_SCROLL_REF,
TuiDestroyService,
tuiGetElementOffset,
tuiScrollFrom,
tuiZoneOptimized,
} from '@taiga-ui/cdk';
import {SCROLL_REF_SELECTOR, TUI_SCROLL_REF} from '@taiga-ui/core';
import {Observable} from 'rxjs';
import {
distinctUntilChanged,
Expand Down
18 changes: 15 additions & 3 deletions projects/cdk/components/dialog-host/dialog-host.component.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import {animateChild, query, style, transition, trigger} from '@angular/animations';
import {DOCUMENT} from '@angular/common';
import {
ChangeDetectionStrategy,
Expand All @@ -9,9 +10,8 @@ import {
} from '@angular/core';
import {Title} from '@angular/platform-browser';
import {HISTORY} from '@ng-web-apis/common';
import {TUI_PARENT_ANIMATION} from '@taiga-ui/cdk/constants';
import {TuiDestroyService} from '@taiga-ui/cdk/services';
import {TUI_DIALOGS} from '@taiga-ui/cdk/tokens';
import {TUI_DIALOGS, TUI_IS_MOBILE} from '@taiga-ui/cdk/tokens';
import {TuiDialog} from '@taiga-ui/cdk/types';
import {tuiCreateToken} from '@taiga-ui/cdk/utils';
import {combineLatest, Observable, of} from 'rxjs';
Expand All @@ -36,14 +36,26 @@ const isFakeHistoryState = (
// eslint-disable-next-line @angular-eslint/prefer-on-push-component-change-detection
changeDetection: ChangeDetectionStrategy.Default,
providers: [TuiDestroyService],
animations: [TUI_PARENT_ANIMATION],
animations: [
trigger('host', [
transition(':enter', [
style({overflow: 'clip'}),
query(':scope > *', [animateChild()], {optional: true}),
]),
transition(':leave', [
style({overflow: 'clip'}),
query(':scope > *', [animateChild()], {optional: true}),
]),
]),
],
})
export class TuiDialogHostComponent<T extends TuiDialog<unknown, unknown>>
implements OnInit
{
dialogs: readonly T[] = [];

constructor(
@Inject(TUI_IS_MOBILE) readonly isMobile: boolean,
@Inject(TUI_DIALOG_CLOSES_ON_BACK)
readonly isDialogClosesOnBack$: Observable<boolean>,
@Inject(TUI_DIALOGS)
Expand Down
10 changes: 7 additions & 3 deletions projects/cdk/components/dialog-host/dialog-host.module.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import {CommonModule} from '@angular/common';
import {NgModule} from '@angular/core';
import {TuiLetModule} from '@taiga-ui/cdk/directives';
import {TuiFocusTrapModule} from '@taiga-ui/cdk/directives/focus-trap';
import {TuiOverscrollModule} from '@taiga-ui/cdk/directives/overscroll';
import {TuiScrollControlsModule} from '@taiga-ui/cdk/components/scroll-controls';
import {
TuiFocusTrapModule,
TuiLetModule,
TuiOverscrollModule,
} from '@taiga-ui/cdk/directives';
import {PolymorpheusModule} from '@tinkoff/ng-polymorpheus';

import {TuiDialogHostComponent} from './dialog-host.component';
Expand All @@ -14,6 +17,7 @@ import {TuiDialogHostComponent} from './dialog-host.component';
TuiOverscrollModule,
TuiFocusTrapModule,
TuiLetModule,
TuiScrollControlsModule,
],
declarations: [TuiDialogHostComponent],
exports: [TuiDialogHostComponent],
Expand Down
26 changes: 23 additions & 3 deletions projects/cdk/components/dialog-host/dialog-host.style.less
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,18 @@
align-items: flex-start;
outline: none;
overflow: auto;
//noinspection CssInvalidPropertyValue
overflow: overlay;

/* stylelint-disable*/
scrollbar-width: none;
-ms-overflow-style: none;
/* stylelint-enable*/

&::-webkit-scrollbar,
&::-webkit-scrollbar-thumb {
background: transparent;
width: 0;
height: 0;
}
}

.t-dialog {
Expand All @@ -35,7 +45,7 @@

/* change of useless property 'letter-spacing' to ensure that transitionend event will fire */
transition:
opacity var(--tui-duration),
opacity var(--tui-duration, 300ms),
letter-spacing 0.01s;
background: rgba(0, 0, 0, 0.75);
backdrop-filter: var(--tui-backdrop, none);
Expand All @@ -49,3 +59,13 @@
.t-dialog:last-of-type {
z-index: 1;
}

.t-scrollbars {
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
margin: 0;
color: #747474;
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,14 @@
tuiOverscroll="all"
tuiScrollRef
class="t-dialog"
@tuiParentAnimation
@host
[attr.aria-labelledby]="item.id"
>
<ng-container *polymorpheusOutlet="item.component; context: item"></ng-container>
<tui-scroll-controls
*ngIf="!isMobile"
class="t-scrollbars"
></tui-scroll-controls>
</section>
<div
*tuiLet="isDialogClosesOnBack$ | async as isDialogClosesOnBack"
Expand Down
1 change: 1 addition & 0 deletions projects/cdk/components/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from '@taiga-ui/cdk/components/alert-host';
export * from '@taiga-ui/cdk/components/dialog-host';
export * from '@taiga-ui/cdk/components/dropdown-host';
export * from '@taiga-ui/cdk/components/scroll-controls';
4 changes: 4 additions & 0 deletions projects/cdk/components/scroll-controls/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export * from './scroll-controls.component';
export * from './scroll-controls.module';
export * from './scroll-ref.directive';
export * from './scrollbar.directive';
5 changes: 5 additions & 0 deletions projects/cdk/components/scroll-controls/ng-package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"lib": {
"entryFile": "index.ts"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import {
ChangeDetectionStrategy,
Component,
ElementRef,
Inject,
NgZone,
} from '@angular/core';
import {ANIMATION_FRAME} from '@ng-web-apis/common';
import {tuiZoneOptimized} from '@taiga-ui/cdk/observables';
import {TUI_SCROLL_REF} from '@taiga-ui/cdk/tokens';
import {Observable} from 'rxjs';
import {distinctUntilChanged, map, startWith, throttleTime} from 'rxjs/operators';

@Component({
selector: 'tui-scroll-controls',
templateUrl: './scroll-controls.template.html',
styleUrls: ['./scroll-controls.style.less'],
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class TuiScrollControlsComponent {
readonly refresh$ = this.animationFrame$.pipe(
throttleTime(300),
map(() => this.scrollbars),
startWith([false, false]),
distinctUntilChanged((a, b) => a[0] === b[0] && a[1] === b[1]),
tuiZoneOptimized(this.zone),
);

constructor(
@Inject(NgZone) private readonly zone: NgZone,
@Inject(TUI_SCROLL_REF) private readonly scrollRef: ElementRef<HTMLElement>,
@Inject(ANIMATION_FRAME) private readonly animationFrame$: Observable<number>,
) {}

private get scrollbars(): [boolean, boolean] {
const {clientHeight, scrollHeight, clientWidth, scrollWidth} =
this.scrollRef.nativeElement;

return [
Math.ceil((clientHeight / scrollHeight) * 100) < 100,
Math.ceil((clientWidth / scrollWidth) * 100) < 100,
];
}
}
17 changes: 17 additions & 0 deletions projects/cdk/components/scroll-controls/scroll-controls.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import {CommonModule} from '@angular/common';
import {NgModule} from '@angular/core';

import {TuiScrollControlsComponent} from './scroll-controls.component';
import {TuiScrollRefDirective} from './scroll-ref.directive';
import {TuiScrollbarDirective} from './scrollbar.directive';

@NgModule({
imports: [CommonModule],
declarations: [
TuiScrollbarDirective,
TuiScrollControlsComponent,
TuiScrollRefDirective,
],
exports: [TuiScrollControlsComponent, TuiScrollRefDirective],
})
export class TuiScrollControlsModule {}
87 changes: 87 additions & 0 deletions projects/cdk/components/scroll-controls/scroll-controls.style.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
@scroll-width: 0.75rem;
@scroll-width-large: 0.875rem;
@scroll-min-size: 1.25rem;

:host {
position: sticky;
top: 0;
left: 0;
z-index: 1;
min-width: calc(100% - 1px);
min-height: calc(100% - 1px);
max-width: calc(100% - 1px);
max-height: calc(100% - 1px);
float: left;
margin-inline-end: calc(-100% + 1px);
pointer-events: none;
}

.t-bar {
position: absolute;
right: 0;
bottom: 0;
pointer-events: auto;
animation: tuiFadeIn var(--tui-duration, 300ms) ease-in-out;

&_vertical {
top: 0;
width: @scroll-width-large;
}

&_horizontal {
left: 0;
height: @scroll-width-large;
}

&_has-horizontal {
bottom: @scroll-width - 0.25rem;
}

&_has-vertical {
right: @scroll-width - 0.25rem;
}
}

.t-thumb {
position: absolute;
border-radius: 6.25rem;
border: 0.25rem solid transparent;
cursor: pointer;
pointer-events: auto;
background: currentColor;
background-clip: content-box;
box-sizing: border-box;
transition: all var(--tui-duration, 300ms) ease-in-out;
transition-property: width, height, opacity;
opacity: 0.2;

&:hover {
opacity: 0.24;
}

&:active {
opacity: 0.48;
}

.t-bar_vertical & {
right: 0;
width: @scroll-width;
min-height: @scroll-min-size;
}

.t-bar_vertical:hover &,
.t-bar_vertical &:active {
width: @scroll-width-large;
}

.t-bar_horizontal & {
bottom: 0;
height: @scroll-width;
min-width: @scroll-min-size;
}

.t-bar_horizontal:hover &,
.t-bar_horizontal &:active {
height: @scroll-width-large;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<ng-container *ngIf="refresh$ | async as bars">
<div
*ngIf="bars[0]"
class="t-bar t-bar_vertical"
[class.t-bar_has-horizontal]="bars[1]"
>
<div
tuiScrollbar="vertical"
class="t-thumb"
></div>
</div>
<div
*ngIf="bars[1]"
class="t-bar t-bar_horizontal"
[class.t-bar_has-vertical]="bars[0]"
>
<div
tuiScrollbar="horizontal"
class="t-thumb"
></div>
</div>
</ng-container>
Loading

0 comments on commit 75358a8

Please sign in to comment.