Skip to content
This repository has been archived by the owner on Feb 2, 2019. It is now read-only.

Commit

Permalink
fix(backdrop): do not dismiss when clicked while animating to show
Browse files Browse the repository at this point in the history
 - add test to verify behavior
  • Loading branch information
justindujardin committed Jan 3, 2016
1 parent 399b5f6 commit f829bd8
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
7 changes: 6 additions & 1 deletion ng2-material/components/backdrop/backdrop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ export class MdBackdrop {


private _visible: boolean = false;
private _transitioning: boolean = false;

/**
* Read-only property indicating whether the backdrop is visible or not.
Expand All @@ -66,7 +67,7 @@ export class MdBackdrop {
}

onClick() {
if (this.clickClose && this.visible) {
if (this.clickClose && !this._transitioning && this.visible) {
this.hide();
}
}
Expand All @@ -80,8 +81,10 @@ export class MdBackdrop {
return Promise.resolve();
}
this._visible = true;
this._transitioning = true;
this.onShowing.emit(this);
return Animate.enter(this.element.nativeElement, 'md-active').then(() => {
this._transitioning = false;
this.onShown.emit(this);
});
}
Expand All @@ -95,8 +98,10 @@ export class MdBackdrop {
return Promise.resolve();
}
this._visible = false;
this._transitioning = true;
this.onHiding.emit(this);
return Animate.leave(this.element.nativeElement, 'md-active').then(() => {
this._transitioning = false;
this.onHidden.emit(this);
});
}
Expand Down
18 changes: 18 additions & 0 deletions test/components/backdrop/backdrop_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,24 @@ export function main() {
async.done();
});
}));
it('should not be clickable during transition animation', inject([AsyncTestCompleter], (async) => {
setup().then((api: IBackdropFixture) => {
let triggered = false;
api.backdrop.clickClose = true;
api.backdrop.hide = () => {
triggered = true;
return Promise.resolve();
};
api.backdrop.show().then(() => {
expect(triggered).toBe(false);
api.debug.nativeElement.click();
expect(triggered).toBe(true);
});
api.debug.nativeElement.click();
expect(triggered).toBe(false);
async.done();
});
}));
});
describe('show', () => {
it('emit events before and after being shown', inject([AsyncTestCompleter], (async) => {
Expand Down

0 comments on commit f829bd8

Please sign in to comment.