@@ -13,7 +13,7 @@ import {
1313 QueryList ,
1414} from '@angular/core' ;
1515import { Direction , Directionality } from '@angular/cdk/bidi' ;
16- import { OverlayContainer } from '@angular/cdk/overlay' ;
16+ import { OverlayContainer , Overlay } from '@angular/cdk/overlay' ;
1717import { ESCAPE , LEFT_ARROW , RIGHT_ARROW } from '@angular/cdk/keycodes' ;
1818import {
1919 MAT_MENU_DEFAULT_OPTIONS ,
@@ -25,7 +25,7 @@ import {
2525 MenuPositionY ,
2626 MatMenuItem ,
2727} from './index' ;
28- import { MENU_PANEL_TOP_PADDING } from './menu-trigger' ;
28+ import { MENU_PANEL_TOP_PADDING , MAT_MENU_SCROLL_STRATEGY } from './menu-trigger' ;
2929import { MatRipple } from '@angular/material/core' ;
3030import {
3131 dispatchKeyboardEvent ,
@@ -35,6 +35,8 @@ import {
3535 createMouseEvent ,
3636 dispatchFakeEvent ,
3737} from '@angular/cdk/testing' ;
38+ import { Subject } from 'rxjs/Subject' ;
39+ import { ScrollDispatcher } from '@angular/cdk/scrolling' ;
3840
3941
4042describe ( 'MatMenu' , ( ) => {
@@ -242,6 +244,40 @@ describe('MatMenu', () => {
242244 expect ( document . activeElement ) . toBe ( panel , 'Expected the panel to be focused.' ) ;
243245 } ) ;
244246
247+ it ( 'should close the menu when using the CloseScrollStrategy' , fakeAsync ( ( ) => {
248+ const scrolledSubject = new Subject ( ) ;
249+
250+ TestBed
251+ . resetTestingModule ( )
252+ . configureTestingModule ( {
253+ imports : [ MatMenuModule , NoopAnimationsModule ] ,
254+ declarations : [ SimpleMenu , FakeIcon ] ,
255+ providers : [
256+ { provide : ScrollDispatcher , useFactory : ( ) => ( { scrolled : ( ) => scrolledSubject } ) } ,
257+ {
258+ provide : MAT_MENU_SCROLL_STRATEGY ,
259+ deps : [ Overlay ] ,
260+ useFactory : ( overlay : Overlay ) => ( ) => overlay . scrollStrategies . close ( )
261+ }
262+ ]
263+ } )
264+ . compileComponents ( ) ;
265+
266+ const fixture = TestBed . createComponent ( SimpleMenu ) ;
267+ const trigger = fixture . componentInstance . trigger ;
268+
269+ fixture . detectChanges ( ) ;
270+ trigger . openMenu ( ) ;
271+ fixture . detectChanges ( ) ;
272+
273+ expect ( trigger . menuOpen ) . toBe ( true ) ;
274+
275+ scrolledSubject . next ( ) ;
276+ tick ( 500 ) ;
277+
278+ expect ( trigger . menuOpen ) . toBe ( false ) ;
279+ } ) ) ;
280+
245281 describe ( 'positions' , ( ) => {
246282 let fixture : ComponentFixture < PositionedMenu > ;
247283 let panel : HTMLElement ;
0 commit comments