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 @@ -1044,6 +1044,21 @@ describe('MDC-based MatMenu', () => {
1044
1044
. toBe ( false ) ;
1045
1045
} ) ;
1046
1046
1047
+ it ( 'should be able to move focus inside the `open` event' , fakeAsync ( ( ) => {
1048
+ const fixture = createComponent ( SimpleMenu , [ ] , [ FakeIcon ] ) ;
1049
+ fixture . detectChanges ( ) ;
1050
+
1051
+ fixture . componentInstance . trigger . menuOpened . subscribe ( ( ) => {
1052
+ ( document . querySelectorAll ( '.mat-mdc-menu-panel [mat-menu-item]' ) [ 3 ] as HTMLElement ) . focus ( ) ;
1053
+ } ) ;
1054
+ fixture . componentInstance . trigger . openMenu ( ) ;
1055
+ fixture . detectChanges ( ) ;
1056
+ tick ( 500 ) ;
1057
+
1058
+ const items = document . querySelectorAll ( '.mat-mdc-menu-panel [mat-menu-item]' ) ;
1059
+ expect ( document . activeElement ) . toBe ( items [ 3 ] , 'Expected fourth item to be focused' ) ;
1060
+ } ) ) ;
1061
+
1047
1062
describe ( 'lazy rendering' , ( ) => {
1048
1063
it ( 'should be able to render the menu content lazily' , fakeAsync ( ( ) => {
1049
1064
const fixture = createComponent ( SimpleLazyMenu ) ;
Original file line number Diff line number Diff line change @@ -339,8 +339,8 @@ export class MatMenuTrigger implements AfterContentInit, OnDestroy {
339
339
this . menu . parentMenu = this . triggersSubmenu ( ) ? this . _parentMaterialMenu : undefined ;
340
340
this . menu . direction = this . dir ;
341
341
this . _setMenuElevation ( ) ;
342
- this . _setIsMenuOpen ( true ) ;
343
342
this . menu . focusFirstItem ( this . _openedBy || 'program' ) ;
343
+ this . _setIsMenuOpen ( true ) ;
344
344
}
345
345
346
346
/** Updates the menu elevation based on the amount of parent menus that it has. */
Original file line number Diff line number Diff line change @@ -987,6 +987,21 @@ describe('MatMenu', () => {
987
987
. toBe ( false ) ;
988
988
} ) ;
989
989
990
+ it ( 'should be able to move focus inside the `open` event' , fakeAsync ( ( ) => {
991
+ const fixture = createComponent ( SimpleMenu , [ ] , [ FakeIcon ] ) ;
992
+ fixture . detectChanges ( ) ;
993
+
994
+ fixture . componentInstance . trigger . menuOpened . subscribe ( ( ) => {
995
+ ( document . querySelectorAll ( '.mat-menu-panel [mat-menu-item]' ) [ 3 ] as HTMLElement ) . focus ( ) ;
996
+ } ) ;
997
+ fixture . componentInstance . trigger . openMenu ( ) ;
998
+ fixture . detectChanges ( ) ;
999
+ tick ( 500 ) ;
1000
+
1001
+ const items = document . querySelectorAll ( '.mat-menu-panel [mat-menu-item]' ) ;
1002
+ expect ( document . activeElement ) . toBe ( items [ 3 ] , 'Expected fourth item to be focused' ) ;
1003
+ } ) ) ;
1004
+
990
1005
describe ( 'lazy rendering' , ( ) => {
991
1006
it ( 'should be able to render the menu content lazily' , fakeAsync ( ( ) => {
992
1007
const fixture = createComponent ( SimpleLazyMenu ) ;
You can’t perform that action at this time.
0 commit comments