Skip to content

Commit

Permalink
fix(core): tui-loader triggers sidebar tuiActiveZoneChange
Browse files Browse the repository at this point in the history
  • Loading branch information
splincode committed Jul 29, 2024
1 parent 0bb7b5b commit 4aee1e6
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 25 deletions.
25 changes: 11 additions & 14 deletions projects/core/components/loader/loader.component.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
import {DOCUMENT} from '@angular/common';
import {
ApplicationRef,
ChangeDetectionStrategy,
ChangeDetectorRef,
Component,
ElementRef,
HostBinding,
Inject,
Input,
} from '@angular/core';
import {
TUI_IS_IOS,
tuiBlurNativeFocused,
tuiIsNativeFocusedIn,
tuiIsSafari,
} from '@taiga-ui/cdk';
import {TUI_IS_IOS, tuiIsSafari} from '@taiga-ui/cdk';
import {tuiSizeBigger} from '@taiga-ui/core/utils/miscellaneous';
import {PolymorpheusContent} from '@tinkoff/ng-polymorpheus';

Expand Down Expand Up @@ -40,8 +36,12 @@ export class TuiLoaderComponent {
@Input()
set showLoader(value: boolean) {
// @bad TODO: https://github.com/angular/angular/issues/32083 think of a better way
if (value && this.focused) {
tuiBlurNativeFocused(this.doc);
if (value) {
this.cd.markForCheck();
/**
* recalculated HostBinding getters
*/
void Promise.resolve().then(() => this.app.tick());
}

this.loading = value;
Expand All @@ -53,7 +53,8 @@ export class TuiLoaderComponent {
readonly isApple = tuiIsSafari(this.el.nativeElement) || this.isIos;

constructor(
@Inject(DOCUMENT) private readonly doc: Document,
@Inject(ApplicationRef) private readonly app: ApplicationRef,
@Inject(ChangeDetectorRef) private readonly cd: ChangeDetectorRef,
@Inject(ElementRef) private readonly el: ElementRef<HTMLElement>,
@Inject(TUI_IS_IOS) private readonly isIos: boolean,
@Inject(TUI_LOADER_OPTIONS) private readonly options: TuiLoaderOptions,
Expand All @@ -70,8 +71,4 @@ export class TuiLoaderComponent {
get isHorizontal(): boolean {
return !tuiSizeBigger(this.size);
}

get focused(): boolean {
return tuiIsNativeFocusedIn(this.el.nativeElement);
}
}
37 changes: 28 additions & 9 deletions projects/demo/src/modules/directives/sidebar/examples/1/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,35 @@
<tui-accordion-item borders="top-bottom">
Other libraries
<ng-template tuiAccordionItemContent>
<a
*ngFor="let link of links"
href="https://github.com/taiga-family/{{ link }}"
rel="noreferrer"
target="_blank"
tuiLink
class="link"
<tui-loader
*tuiLet="fakeRequest$ | async as loading"
textContent="Loading..."
[overlay]="true"
[showLoader]="loading || false"
>
{{ link }}
</a>
<ng-container *ngIf="loading === false; else button">
<a
*ngFor="let link of links"
href="https://github.com/taiga-family/{{ link }}"
rel="noreferrer"
target="_blank"
tuiLink
class="link"
>
{{ link }}
</a>
</ng-container>

<ng-template #button>
<button
size="s"
tuiButton
(click)="load$.next()"
>
Loading
</button>
</ng-template>
</tui-loader>
</ng-template>
</tui-accordion-item>
</tui-accordion>
Expand Down
12 changes: 12 additions & 0 deletions projects/demo/src/modules/directives/sidebar/examples/1/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import {Component} from '@angular/core';
import {changeDetection} from '@demo/emulate/change-detection';
import {encapsulation} from '@demo/emulate/encapsulation';
import {ALWAYS_FALSE_HANDLER, tuiPure} from '@taiga-ui/cdk';
import {Observable, Subject, timer} from 'rxjs';
import {map, startWith, switchMap} from 'rxjs/operators';

@Component({
selector: 'tui-sidebar-example-1',
Expand All @@ -10,12 +13,21 @@ import {encapsulation} from '@demo/emulate/encapsulation';
changeDetection,
})
export class TuiSidebarExample1 {
readonly load$ = new Subject<void>();

open = false;

readonly webApis = ['Common', 'Audio', 'Canvas', 'Geolocation', 'MIDI', 'Workers'];

readonly links = ['Taiga-UI', 'ng-event-plugins', 'ng-polymorpheus', 'ng-dompurify'];

@tuiPure
get fakeRequest$(): Observable<boolean> {
return this.load$.pipe(
switchMap(() => timer(2000).pipe(map(ALWAYS_FALSE_HANDLER), startWith(true))),
);
}

toggle(open: boolean): void {
this.open = open;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import {NgModule} from '@angular/core';
import {RouterModule} from '@angular/router';
import {TuiAddonDocModule, tuiGenerateRoutes} from '@taiga-ui/addon-doc';
import {TuiSidebarModule} from '@taiga-ui/addon-mobile';
import {TuiActiveZoneModule} from '@taiga-ui/cdk';
import {TuiButtonModule, TuiLinkModule} from '@taiga-ui/core';
import {TuiActiveZoneModule, TuiLetModule} from '@taiga-ui/cdk';
import {TuiButtonModule, TuiLinkModule, TuiLoaderModule} from '@taiga-ui/core';
import {TuiAccordionModule} from '@taiga-ui/kit';

import {TuiSidebarExample1} from './examples/1';
Expand All @@ -20,6 +20,8 @@ import {ExampleTuiSidebarComponent} from './sidebar.component';
TuiLinkModule,
TuiAddonDocModule,
RouterModule.forChild(tuiGenerateRoutes(ExampleTuiSidebarComponent)),
TuiLoaderModule,
TuiLetModule,
],
declarations: [ExampleTuiSidebarComponent, TuiSidebarExample1],
exports: [ExampleTuiSidebarComponent],
Expand Down

0 comments on commit 4aee1e6

Please sign in to comment.