@@ -164,6 +164,23 @@ describe('MatMenu', () => {
164
164
expect ( document . activeElement ) . toBe ( triggerEl ) ;
165
165
} ) ) ;
166
166
167
+ it ( 'should scroll the panel to the top on open, when it is scrollable' , fakeAsync ( ( ) => {
168
+ const fixture = createComponent ( SimpleMenu , [ ] , [ FakeIcon ] ) ;
169
+ fixture . detectChanges ( ) ;
170
+
171
+ // Add 50 items to make the menu scrollable
172
+ fixture . componentInstance . extraItems = new Array ( 50 ) . fill ( 'Hello there' ) ;
173
+ fixture . detectChanges ( ) ;
174
+
175
+ const triggerEl = fixture . componentInstance . triggerEl . nativeElement ;
176
+ dispatchFakeEvent ( triggerEl , 'mousedown' ) ;
177
+ triggerEl . click ( ) ;
178
+ fixture . detectChanges ( ) ;
179
+ tick ( ) ;
180
+
181
+ expect ( overlayContainerElement . querySelector ( '.mat-menu-panel' ) ! . scrollTop ) . toBe ( 0 ) ;
182
+ } ) ) ;
183
+
167
184
it ( 'should set the proper focus origin when restoring focus after opening by keyboard' ,
168
185
fakeAsync ( ( ) => {
169
186
const fixture = createComponent ( SimpleMenu , [ ] , [ FakeIcon ] ) ;
@@ -1674,6 +1691,7 @@ describe('MatMenu default overrides', () => {
1674
1691
<fake-icon>unicorn</fake-icon>
1675
1692
Item with an icon
1676
1693
</button>
1694
+ <button *ngFor="let item of extraItems" mat-menu-item> {{item}} </button>
1677
1695
</mat-menu>
1678
1696
`
1679
1697
} )
@@ -1682,6 +1700,7 @@ class SimpleMenu {
1682
1700
@ViewChild ( 'triggerEl' ) triggerEl : ElementRef ;
1683
1701
@ViewChild ( MatMenu ) menu : MatMenu ;
1684
1702
@ViewChildren ( MatMenuItem ) items : QueryList < MatMenuItem > ;
1703
+ extraItems : string [ ] = [ ] ;
1685
1704
closeCallback = jasmine . createSpy ( 'menu closed callback' ) ;
1686
1705
backdropClass : string ;
1687
1706
}
0 commit comments