@@ -18,6 +18,36 @@ it('moves the focus to the first menu item after pressing enter while focused on
1818 expect ( document . activeElement ?. id ) . toBe ( 'menu-item-1' ) ;
1919} ) ;
2020
21+ it ( 'moves the focus to the first menu item after pressing space while focused on the menu button' , ( ) => {
22+ const component = mount ( < TestComponent /> ) ;
23+ const button = component . find ( '#menu-button' ) ;
24+
25+ button . getDOMNode < HTMLButtonElement > ( ) . focus ( ) ;
26+ button . simulate ( 'keydown' , { key : ' ' } ) ;
27+
28+ expect ( document . activeElement ?. id ) . toBe ( 'menu-item-1' ) ;
29+ } ) ;
30+
31+ it ( 'moves the focus to the first menu item after clicking the menu to open it, then pressing tab while focused on the menu button' , ( ) => {
32+ const component = mount ( < TestComponent /> ) ;
33+ const button = component . find ( '#menu-button' ) ;
34+
35+ button . simulate ( 'click' ) ;
36+ button . simulate ( 'keydown' , { key : 'Tab' } ) ;
37+
38+ expect ( document . activeElement ?. id ) . toBe ( 'menu-item-1' ) ;
39+ } ) ;
40+
41+ it ( 'moves the focus to the first menu item after clicking the menu to open it, then pressing arrow down while focused on the menu button' , ( ) => {
42+ const component = mount ( < TestComponent /> ) ;
43+ const button = component . find ( '#menu-button' ) ;
44+
45+ button . simulate ( 'click' ) ;
46+ button . simulate ( 'keydown' , { key : 'ArrowDown' } ) ;
47+
48+ expect ( document . activeElement ?. id ) . toBe ( 'menu-item-1' ) ;
49+ } ) ;
50+
2151it ( 'sets isOpen to true after pressing enter while focused on the menu button' , ( ) => {
2252 const component = mount ( < TestComponent /> ) ;
2353 const button = component . find ( '#menu-button' ) ;
@@ -29,6 +59,17 @@ it('sets isOpen to true after pressing enter while focused on the menu button',
2959 expect ( span . text ( ) ) . toBe ( 'true' ) ;
3060} ) ;
3161
62+ it ( 'sets isOpen to true after pressing space while focused on the menu button' , ( ) => {
63+ const component = mount ( < TestComponent /> ) ;
64+ const button = component . find ( '#menu-button' ) ;
65+ const span = component . find ( '#is-open-indicator' ) ;
66+
67+ button . getDOMNode < HTMLButtonElement > ( ) . focus ( ) ;
68+ button . simulate ( 'keydown' , { key : ' ' } ) ;
69+
70+ expect ( span . text ( ) ) . toBe ( 'true' ) ;
71+ } ) ;
72+
3273it ( 'moves the focus to the next element in the menu after pressing the down arrow' , ( ) => {
3374 const component = mount ( < TestComponent /> ) ;
3475 const button = component . find ( '#menu-button' ) ;
0 commit comments