Skip to content

Commit

Permalink
fix(modals): modal backdrop and onclick events handling
Browse files Browse the repository at this point in the history
fixes #687, fixes #703, closes #708

1. This fix will resolve the issue of backdrop being displayed even when
the user sets backdrop as false.

2. This will provide option to users to control ignore backdrop clicks.
  • Loading branch information
pradeepsekar authored and valorkin committed Jul 11, 2016
1 parent c994f8f commit b39b856
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
4 changes: 4 additions & 0 deletions components/modal/modal-options.class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ export interface ModalOptions {
* Shows the modal when initialized.
*/
show:boolean;
/**
* Ignore the backdrop click
*/
ignoreBackdropClick:boolean;
}

export const modalConfigDefaults:ModalOptions = {
Expand Down
7 changes: 2 additions & 5 deletions components/modal/modal.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ export class ModalDirective implements AfterViewInit, OnDestroy {
protected _isShown:boolean = false;

private isBodyOverflowing:boolean = false;
private ignoreBackdropClick:boolean = false;
private originalBodyPadding:number = 0;
private scrollbarWidth:number = 0;

Expand All @@ -76,8 +75,7 @@ export class ModalDirective implements AfterViewInit, OnDestroy {

@HostListener('click', ['$event'])
protected onClick(event:any):void {
if (this.config.backdrop !== 'static' &&
event.target === this.element.nativeElement) {
if (this.config.ignoreBackdropClick || this.config.backdrop === 'static') {
this.hide(event);
}
}
Expand Down Expand Up @@ -107,7 +105,6 @@ export class ModalDirective implements AfterViewInit, OnDestroy {
// this._backdrop = null
this._isShown = void 0;
this.isBodyOverflowing = void 0;
this.ignoreBackdropClick = void 0;
this.originalBodyPadding = void 0;
this.scrollbarWidth = void 0;

Expand Down Expand Up @@ -226,7 +223,7 @@ export class ModalDirective implements AfterViewInit, OnDestroy {

// todo: original show was calling a callback when done, but we can use promise
private showBackdrop(callback?:Function):void {
if (this._isShown && modalConfigDefaults.backdrop) {
if (this._isShown && this.config.backdrop) {
this.backdrop = this.componentsHelper
.appendNextToRoot(
ModalBackdropComponent,
Expand Down

0 comments on commit b39b856

Please sign in to comment.