File tree Expand file tree Collapse file tree 3 files changed +31
-1
lines changed Expand file tree Collapse file tree 3 files changed +31
-1
lines changed Original file line number Diff line number Diff line change @@ -994,6 +994,21 @@ describe('MDC-based MatMenu', () => {
994
994
. toBe ( overlayContainerElement . querySelector ( '.mat-mdc-menu-panel' ) ) ;
995
995
} ) ) ;
996
996
997
+ it ( 'should be able to move focus inside the `open` event' , fakeAsync ( ( ) => {
998
+ const fixture = createComponent ( SimpleMenu , [ ] , [ FakeIcon ] ) ;
999
+ fixture . detectChanges ( ) ;
1000
+
1001
+ fixture . componentInstance . trigger . menuOpened . subscribe ( ( ) => {
1002
+ ( document . querySelectorAll ( '.mat-mdc-menu-panel [mat-menu-item]' ) [ 3 ] as HTMLElement ) . focus ( ) ;
1003
+ } ) ;
1004
+ fixture . componentInstance . trigger . openMenu ( ) ;
1005
+ fixture . detectChanges ( ) ;
1006
+ tick ( 500 ) ;
1007
+
1008
+ const items = document . querySelectorAll ( '.mat-mdc-menu-panel [mat-menu-item]' ) ;
1009
+ expect ( document . activeElement ) . toBe ( items [ 3 ] , 'Expected fourth item to be focused' ) ;
1010
+ } ) ) ;
1011
+
997
1012
describe ( 'lazy rendering' , ( ) => {
998
1013
it ( 'should be able to render the menu content lazily' , fakeAsync ( ( ) => {
999
1014
const fixture = createComponent ( SimpleLazyMenu ) ;
Original file line number Diff line number Diff line change @@ -331,8 +331,8 @@ export class MatMenuTrigger implements AfterContentInit, OnDestroy {
331
331
this . menu . parentMenu = this . triggersSubmenu ( ) ? this . _parentMaterialMenu : undefined ;
332
332
this . menu . direction = this . dir ;
333
333
this . _setMenuElevation ( ) ;
334
- this . _setIsMenuOpen ( true ) ;
335
334
this . menu . focusFirstItem ( this . _openedBy || 'program' ) ;
335
+ this . _setIsMenuOpen ( true ) ;
336
336
}
337
337
338
338
/** Updates the menu elevation based on the amount of parent menus that it has. */
Original file line number Diff line number Diff line change @@ -932,6 +932,21 @@ describe('MatMenu', () => {
932
932
expect ( document . activeElement ) . toBe ( overlayContainerElement . querySelector ( '.mat-menu-panel' ) ) ;
933
933
} ) ) ;
934
934
935
+ it ( 'should be able to move focus inside the `open` event' , fakeAsync ( ( ) => {
936
+ const fixture = createComponent ( SimpleMenu , [ ] , [ FakeIcon ] ) ;
937
+ fixture . detectChanges ( ) ;
938
+
939
+ fixture . componentInstance . trigger . menuOpened . subscribe ( ( ) => {
940
+ ( document . querySelectorAll ( '.mat-menu-panel [mat-menu-item]' ) [ 3 ] as HTMLElement ) . focus ( ) ;
941
+ } ) ;
942
+ fixture . componentInstance . trigger . openMenu ( ) ;
943
+ fixture . detectChanges ( ) ;
944
+ tick ( 500 ) ;
945
+
946
+ const items = document . querySelectorAll ( '.mat-menu-panel [mat-menu-item]' ) ;
947
+ expect ( document . activeElement ) . toBe ( items [ 3 ] , 'Expected fourth item to be focused' ) ;
948
+ } ) ) ;
949
+
935
950
describe ( 'lazy rendering' , ( ) => {
936
951
it ( 'should be able to render the menu content lazily' , fakeAsync ( ( ) => {
937
952
const fixture = createComponent ( SimpleLazyMenu ) ;
You can’t perform that action at this time.
0 commit comments