@@ -913,6 +913,25 @@ describe('<Autocomplete />', () => {
913
913
expect ( textbox . selectionStart ) . to . equal ( 0 ) ;
914
914
expect ( textbox . selectionEnd ) . to . equal ( 3 ) ;
915
915
} ) ;
916
+
917
+ it ( 'should focus the input when clicking on the open action' , ( ) => {
918
+ const { getByRole, queryByTitle } = render (
919
+ < Autocomplete
920
+ { ...defaultProps }
921
+ value = "one"
922
+ options = { [ 'one' , 'two' ] }
923
+ renderInput = { params => < TextField { ...params } /> }
924
+ /> ,
925
+ ) ;
926
+
927
+ const textbox = getByRole ( 'textbox' ) ;
928
+ fireEvent . click ( textbox ) ;
929
+ expect ( textbox ) . to . have . focus ;
930
+ textbox . blur ( ) ;
931
+
932
+ fireEvent . click ( queryByTitle ( 'Open' ) ) ;
933
+ expect ( textbox ) . to . have . focus ;
934
+ } ) ;
916
935
} ) ;
917
936
918
937
describe ( 'controlled' , ( ) => {
@@ -1141,8 +1160,7 @@ describe('<Autocomplete />', () => {
1141
1160
fireEvent . click ( firstOption ) ;
1142
1161
expect ( textbox ) . to . not . have . focus ;
1143
1162
1144
- const opener = queryByTitle ( 'Open' ) ;
1145
- fireEvent . click ( opener ) ;
1163
+ fireEvent . click ( queryByTitle ( 'Open' ) ) ;
1146
1164
expect ( textbox ) . to . have . focus ;
1147
1165
firstOption = getByRole ( 'option' ) ;
1148
1166
fireEvent . touchStart ( firstOption ) ;
@@ -1166,8 +1184,7 @@ describe('<Autocomplete />', () => {
1166
1184
fireEvent . click ( firstOption ) ;
1167
1185
expect ( textbox ) . to . have . focus ;
1168
1186
1169
- const opener = queryByTitle ( 'Open' ) ;
1170
- fireEvent . click ( opener ) ;
1187
+ fireEvent . click ( queryByTitle ( 'Open' ) ) ;
1171
1188
firstOption = getByRole ( 'option' ) ;
1172
1189
fireEvent . touchStart ( firstOption ) ;
1173
1190
fireEvent . click ( firstOption ) ;
@@ -1191,8 +1208,7 @@ describe('<Autocomplete />', () => {
1191
1208
fireEvent . click ( firstOption ) ;
1192
1209
expect ( textbox ) . to . have . focus ;
1193
1210
1194
- const opener = queryByTitle ( 'Open' ) ;
1195
- fireEvent . click ( opener ) ;
1211
+ fireEvent . click ( queryByTitle ( 'Open' ) ) ;
1196
1212
firstOption = getByRole ( 'option' ) ;
1197
1213
fireEvent . click ( firstOption ) ;
1198
1214
expect ( textbox ) . to . not . have . focus ;
0 commit comments