@@ -13,7 +13,7 @@ import {
13
13
QueryList ,
14
14
} from '@angular/core' ;
15
15
import { Direction , Directionality } from '@angular/cdk/bidi' ;
16
- import { OverlayContainer } from '@angular/cdk/overlay' ;
16
+ import { OverlayContainer , Overlay } from '@angular/cdk/overlay' ;
17
17
import { ESCAPE , LEFT_ARROW , RIGHT_ARROW } from '@angular/cdk/keycodes' ;
18
18
import {
19
19
MAT_MENU_DEFAULT_OPTIONS ,
@@ -25,7 +25,7 @@ import {
25
25
MenuPositionY ,
26
26
MatMenuItem ,
27
27
} from './index' ;
28
- import { MENU_PANEL_TOP_PADDING } from './menu-trigger' ;
28
+ import { MENU_PANEL_TOP_PADDING , MAT_MENU_SCROLL_STRATEGY } from './menu-trigger' ;
29
29
import { MatRipple } from '@angular/material/core' ;
30
30
import {
31
31
dispatchKeyboardEvent ,
@@ -35,6 +35,8 @@ import {
35
35
createMouseEvent ,
36
36
dispatchFakeEvent ,
37
37
} from '@angular/cdk/testing' ;
38
+ import { Subject } from 'rxjs/Subject' ;
39
+ import { ScrollDispatcher } from '@angular/cdk/scrolling' ;
38
40
39
41
40
42
describe ( 'MatMenu' , ( ) => {
@@ -242,6 +244,40 @@ describe('MatMenu', () => {
242
244
expect ( document . activeElement ) . toBe ( panel , 'Expected the panel to be focused.' ) ;
243
245
} ) ;
244
246
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
+
245
281
describe ( 'positions' , ( ) => {
246
282
let fixture : ComponentFixture < PositionedMenu > ;
247
283
let panel : HTMLElement ;
0 commit comments