Skip to content

Commit 941cb1d

Browse files
committed
fix(backdrop): use raf when adding/removing disable-scroll css
1 parent 6564266 commit 941cb1d

File tree

1 file changed

+17
-14
lines changed

1 file changed

+17
-14
lines changed

src/components/backdrop/backdrop.ts

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
import {Directive, ViewEncapsulation, HostListener, ElementRef, Input} from '@angular/core';
2-
import {isTrueProperty} from '../../util/util';
1+
import { Directive, ElementRef, Input } from '@angular/core';
2+
3+
import { isTrueProperty} from '../../util/util';
4+
import { nativeRaf} from '../../util/dom';
35

46
const DISABLE_SCROLL = 'disable-scroll';
57

@@ -19,23 +21,24 @@ export class Backdrop {
1921

2022
private static push() {
2123
if (this.nuBackDrops === 0) {
22-
console.debug('adding .disable-scroll to body');
23-
document.body.classList.add(DISABLE_SCROLL);
24-
} else {
25-
console.warn('several backdrops on screen? probably a bug');
24+
nativeRaf(() => {
25+
console.debug('adding .disable-scroll to body');
26+
document.body.classList.add(DISABLE_SCROLL);
27+
});
2628
}
2729
this.nuBackDrops++;
2830
}
2931

3032
private static pop() {
31-
if (this.nuBackDrops === 0) {
32-
console.error('pop requires a push');
33-
return;
34-
}
35-
this.nuBackDrops--;
36-
if (this.nuBackDrops === 0) {
37-
console.debug('removing .disable-scroll from body');
38-
document.body.classList.remove(DISABLE_SCROLL);
33+
if (this.nuBackDrops > 0) {
34+
this.nuBackDrops--;
35+
36+
if (this.nuBackDrops === 0) {
37+
nativeRaf(() => {
38+
console.debug('removing .disable-scroll from body');
39+
document.body.classList.remove(DISABLE_SCROLL);
40+
});
41+
}
3942
}
4043
}
4144

0 commit comments

Comments
 (0)