Skip to content

Commit

Permalink
fix(backdrop): use raf when adding/removing disable-scroll css
Browse files Browse the repository at this point in the history
  • Loading branch information
adamdbradley committed Jul 1, 2016
1 parent 6564266 commit 941cb1d
Showing 1 changed file with 17 additions and 14 deletions.
31 changes: 17 additions & 14 deletions src/components/backdrop/backdrop.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import {Directive, ViewEncapsulation, HostListener, ElementRef, Input} from '@angular/core';
import {isTrueProperty} from '../../util/util';
import { Directive, ElementRef, Input } from '@angular/core';

import { isTrueProperty} from '../../util/util';
import { nativeRaf} from '../../util/dom';

const DISABLE_SCROLL = 'disable-scroll';

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

private static push() {
if (this.nuBackDrops === 0) {
console.debug('adding .disable-scroll to body');
document.body.classList.add(DISABLE_SCROLL);
} else {
console.warn('several backdrops on screen? probably a bug');
nativeRaf(() => {
console.debug('adding .disable-scroll to body');
document.body.classList.add(DISABLE_SCROLL);
});
}
this.nuBackDrops++;
}

private static pop() {
if (this.nuBackDrops === 0) {
console.error('pop requires a push');
return;
}
this.nuBackDrops--;
if (this.nuBackDrops === 0) {
console.debug('removing .disable-scroll from body');
document.body.classList.remove(DISABLE_SCROLL);
if (this.nuBackDrops > 0) {
this.nuBackDrops--;

if (this.nuBackDrops === 0) {
nativeRaf(() => {
console.debug('removing .disable-scroll from body');
document.body.classList.remove(DISABLE_SCROLL);
});
}
}
}

Expand Down

0 comments on commit 941cb1d

Please sign in to comment.