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 @@ -1014,6 +1014,21 @@ describe('MDC-based MatMenu', () => {
1014
1014
. toBe ( false ) ;
1015
1015
} ) ;
1016
1016
1017
+ it ( 'should be able to move focus inside the `open` event' , fakeAsync ( ( ) => {
1018
+ const fixture = createComponent ( SimpleMenu , [ ] , [ FakeIcon ] ) ;
1019
+ fixture . detectChanges ( ) ;
1020
+
1021
+ fixture . componentInstance . trigger . menuOpened . subscribe ( ( ) => {
1022
+ ( document . querySelectorAll ( '.mat-mdc-menu-panel [mat-menu-item]' ) [ 3 ] as HTMLElement ) . focus ( ) ;
1023
+ } ) ;
1024
+ fixture . componentInstance . trigger . openMenu ( ) ;
1025
+ fixture . detectChanges ( ) ;
1026
+ tick ( 500 ) ;
1027
+
1028
+ const items = document . querySelectorAll ( '.mat-mdc-menu-panel [mat-menu-item]' ) ;
1029
+ expect ( document . activeElement ) . toBe ( items [ 3 ] , 'Expected fourth item to be focused' ) ;
1030
+ } ) ) ;
1031
+
1017
1032
describe ( 'lazy rendering' , ( ) => {
1018
1033
it ( 'should be able to render the menu content lazily' , fakeAsync ( ( ) => {
1019
1034
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 @@ -957,6 +957,21 @@ describe('MatMenu', () => {
957
957
. toBe ( false ) ;
958
958
} ) ;
959
959
960
+ it ( 'should be able to move focus inside the `open` event' , fakeAsync ( ( ) => {
961
+ const fixture = createComponent ( SimpleMenu , [ ] , [ FakeIcon ] ) ;
962
+ fixture . detectChanges ( ) ;
963
+
964
+ fixture . componentInstance . trigger . menuOpened . subscribe ( ( ) => {
965
+ ( document . querySelectorAll ( '.mat-menu-panel [mat-menu-item]' ) [ 3 ] as HTMLElement ) . focus ( ) ;
966
+ } ) ;
967
+ fixture . componentInstance . trigger . openMenu ( ) ;
968
+ fixture . detectChanges ( ) ;
969
+ tick ( 500 ) ;
970
+
971
+ const items = document . querySelectorAll ( '.mat-menu-panel [mat-menu-item]' ) ;
972
+ expect ( document . activeElement ) . toBe ( items [ 3 ] , 'Expected fourth item to be focused' ) ;
973
+ } ) ) ;
974
+
960
975
describe ( 'lazy rendering' , ( ) => {
961
976
it ( 'should be able to render the menu content lazily' , fakeAsync ( ( ) => {
962
977
const fixture = createComponent ( SimpleLazyMenu ) ;
You can’t perform that action at this time.
0 commit comments