Skip to content

Commit

Permalink
fix(menu): backdrop click without 300ms delay
Browse files Browse the repository at this point in the history
fixes #6405
  • Loading branch information
manucorporat committed Sep 30, 2016
1 parent 87330b3 commit 9bbe485
Showing 1 changed file with 16 additions and 20 deletions.
36 changes: 16 additions & 20 deletions src/components/menu/menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { MenuController } from './menu-controller';
import { MenuType } from './menu-types';
import { Platform } from '../../platform/platform';
import { GestureController } from '../../gestures/gesture-controller';
import { UIEventManager } from '../../util/ui-event-manager';


/**
Expand Down Expand Up @@ -178,7 +179,7 @@ import { GestureController } from '../../gestures/gesture-controller';
selector: 'ion-menu',
template:
'<div class="menu-inner"><ng-content></ng-content></div>' +
'<ion-backdrop (click)="bdClick($event)" disableScroll="false"></ion-backdrop>',
'<ion-backdrop disableScroll="false"></ion-backdrop>',
host: {
'role': 'navigation'
},
Expand All @@ -195,7 +196,7 @@ export class Menu {
private _isAnimating: boolean = false;
private _isPers: boolean = false;
private _init: boolean = false;

private _events: UIEventManager = new UIEventManager();

/**
* @private
Expand All @@ -207,11 +208,6 @@ export class Menu {
*/
@ViewChild(Backdrop) backdrop: Backdrop;

/**
* @private
*/
onContentClick: EventListener;

/**
* @input {any} A reference to the content element the menu should use.
*/
Expand Down Expand Up @@ -349,15 +345,6 @@ export class Menu {
}
self._setListeners();

// create a reusable click handler on this instance, but don't assign yet
self.onContentClick = function(ev: UIEvent) {
if (self._isEnabled) {
ev.preventDefault();
ev.stopPropagation();
self.close();
}
};

self._cntEle.classList.add('menu-content');
self._cntEle.classList.add('menu-content-' + self.type);

Expand All @@ -368,11 +355,11 @@ export class Menu {
/**
* @private
*/
bdClick(ev: Event) {
console.debug('backdrop clicked');
onBackdropClick(ev: UIEvent): boolean {
ev.preventDefault();
ev.stopPropagation();
this._menuCtrl.close();
return false;
}

/**
Expand Down Expand Up @@ -502,10 +489,18 @@ export class Menu {

(<any>this._cntEle.classList)[isOpen ? 'add' : 'remove']('menu-content-open');

this._cntEle.removeEventListener('click', this.onContentClick);
this._events.unlistenAll();

if (isOpen) {
this._cntEle.addEventListener('click', this.onContentClick);
let callback = this.onBackdropClick.bind(this);
this._events.pointerEvents({
element: this._cntEle,
pointerDown: callback
});
this._events.pointerEvents({
element: this.backdrop.getNativeElement(),
pointerDown: callback
});
this.ionOpen.emit(true);

} else {
Expand Down Expand Up @@ -612,6 +607,7 @@ export class Menu {
*/
ngOnDestroy() {
this._menuCtrl.unregister(this);
this._events.unlistenAll();
this._cntGesture && this._cntGesture.destroy();
this._type && this._type.destroy();
this._resizeUnreg && this._resizeUnreg();
Expand Down

0 comments on commit 9bbe485

Please sign in to comment.