@@ -23,6 +23,7 @@ import {
2323 HorizontalConnectionPos ,
2424 VerticalConnectionPos
2525} from '../core' ;
26+ import { Subscription } from 'rxjs/Subscription' ;
2627
2728/**
2829 * This directive is intended to be used in conjunction with an md-menu tag. It is
@@ -40,6 +41,7 @@ export class MdMenuTrigger implements AfterViewInit, OnDestroy {
4041 private _portal : TemplatePortal ;
4142 private _overlayRef : OverlayRef ;
4243 private _menuOpen : boolean = false ;
44+ private _backdropSubscription : Subscription ;
4345
4446 // tracking input type is necessary so it's possible to only auto-focus
4547 // the first item of the list when the menu is opened via the keyboard
@@ -70,13 +72,15 @@ export class MdMenuTrigger implements AfterViewInit, OnDestroy {
7072 if ( ! this . _menuOpen ) {
7173 this . _createOverlay ( ) ;
7274 this . _overlayRef . attach ( this . _portal ) ;
75+ this . _subscribeToBackdrop ( ) ;
7376 this . _initMenu ( ) ;
7477 }
7578 }
7679
7780 closeMenu ( ) : void {
7881 if ( this . _overlayRef ) {
7982 this . _overlayRef . detach ( ) ;
83+ this . _backdropSubscription . unsubscribe ( ) ;
8084 this . _resetMenu ( ) ;
8185 }
8286 }
@@ -92,6 +96,15 @@ export class MdMenuTrigger implements AfterViewInit, OnDestroy {
9296 this . _renderer . invokeElementMethod ( this . _element . nativeElement , 'focus' ) ;
9397 }
9498
99+ /**
100+ * This method ensures that the menu closes when the overlay backdrop is clicked.
101+ */
102+ private _subscribeToBackdrop ( ) : void {
103+ this . _backdropSubscription = this . _overlayRef . backdropClick ( ) . subscribe ( ( ) => {
104+ this . closeMenu ( ) ;
105+ } ) ;
106+ }
107+
95108 /**
96109 * This method sets the menu state to open and focuses the first item if
97110 * the menu was opened via the keyboard.
@@ -120,7 +133,6 @@ export class MdMenuTrigger implements AfterViewInit, OnDestroy {
120133 // set state rather than toggle to support triggers sharing a menu
121134 private _setIsMenuOpen ( isOpen : boolean ) : void {
122135 this . _menuOpen = isOpen ;
123- this . menu . _setClickCatcher ( isOpen ) ;
124136 this . _menuOpen ? this . onMenuOpen . emit ( null ) : this . onMenuClose . emit ( null ) ;
125137 }
126138
@@ -152,6 +164,8 @@ export class MdMenuTrigger implements AfterViewInit, OnDestroy {
152164 private _getOverlayConfig ( ) : OverlayState {
153165 const overlayState = new OverlayState ( ) ;
154166 overlayState . positionStrategy = this . _getPosition ( ) ;
167+ overlayState . hasBackdrop = true ;
168+ overlayState . backdropClass = 'md-overlay-transparent-backdrop' ;
155169 return overlayState ;
156170 }
157171
0 commit comments