Skip to content

Commit 4c521b1

Browse files
committed
Add the 'backdrop' option, which allows to make the spinner background clickable.
1 parent f5b8345 commit 4c521b1

File tree

4 files changed

+44
-9
lines changed

4 files changed

+44
-9
lines changed

src/lib/components/ng-http-loader.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<div id="spinner" *ngIf="isVisible$ | async">
1+
<div id="spinner" [class.backdrop]="backdrop" *ngIf="isVisible$ | async">
22

33
<ng-container *ngComponentOutlet="entryComponent"></ng-container>
44

src/lib/components/ng-http-loader.component.scss

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,24 @@
11
@import "variables";
22

33
#spinner {
4-
top: 0;
5-
left: 0;
6-
height: 100%;
7-
width: 100%;
4+
top: 50% ;
5+
left: 50%;
6+
transform: translate(-50%, -50%);
87
position: fixed;
98
z-index: 9999;
10-
display: flex;
11-
align-items: center;
12-
justify-content: center;
139
opacity: $spinner-opacity;
14-
background-color: $spinner-background-color;
10+
11+
&.backdrop {
12+
top: 0;
13+
left: 0;
14+
height: 100%;
15+
width: 100%;
16+
background-color: $spinner-background-color;
17+
display: flex;
18+
align-items: center;
19+
justify-content: center;
20+
transform: none;
21+
}
1522
}
1623

1724
::ng-deep .colored-parent, ::ng-deep .colored > div {

src/lib/components/ng-http-loader.component.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ export class NgHttpLoaderComponent implements OnDestroy, OnInit {
4343
public extraDuration = 0;
4444
@Input()
4545
public entryComponent: any = null;
46+
@Input()
47+
public backdrop = true;
4648

4749
constructor(private pendingRequestsInterceptor: PendingRequestsInterceptor, private spinnerVisibility: SpinnerVisibilityService) {
4850
const [showSpinner$, hideSpinner$] = partition((h: boolean) => h)(this.pendingRequestsInterceptor.pendingRequestsStatus$);

src/test/components/ng-http-loader.component.spec.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -852,4 +852,30 @@ describe('NgHttpLoaderComponent', () => {
852852
component.isVisible$.subscribe(v => expect(v).toBeFalsy()).unsubscribe();
853853
}
854854
)));
855+
856+
it('should set the backdrop CSS class by default', () => {
857+
spyOnProperty(component, 'isVisible$')
858+
.and.returnValue(new BehaviorSubject(true).asObservable());
859+
fixture.detectChanges();
860+
861+
const element = fixture
862+
.debugElement
863+
.query(By.css('.backdrop'))
864+
.nativeElement;
865+
866+
expect(element).toBeTruthy();
867+
});
868+
869+
it('should be possible to remove the backdrop class', () => {
870+
spyOnProperty(component, 'isVisible$')
871+
.and.returnValue(new BehaviorSubject(true).asObservable());
872+
component.backdrop = false;
873+
fixture.detectChanges();
874+
875+
const element = fixture
876+
.debugElement
877+
.query(By.css('.backdrop'));
878+
879+
expect(element).toBeNull();
880+
});
855881
});

0 commit comments

Comments
 (0)