File tree Expand file tree Collapse file tree 2 files changed +22
-2
lines changed Expand file tree Collapse file tree 2 files changed +22
-2
lines changed Original file line number Diff line number Diff line change @@ -321,4 +321,22 @@ describe("userEvent.click", () => {
321
321
userEvent . click ( getByText ( "Submit" ) ) ;
322
322
expect ( onSubmit ) . not . toHaveBeenCalled ( ) ;
323
323
} ) ;
324
+
325
+ it . each ( [ "input" , "textarea" ] ) (
326
+ "should not give focus for <%s> when mouseDown is prevented" ,
327
+ type => {
328
+ const { getByTestId } = render (
329
+ React . createElement ( type , {
330
+ "data-testid" : "element" ,
331
+ onMouseDown : ( evt ) => {
332
+ evt . preventDefault ( ) ;
333
+ } ,
334
+ } )
335
+ ) ;
336
+
337
+ userEvent . click ( getByTestId ( "element" ) ) ;
338
+
339
+ expect ( getByTestId ( "element" ) ) . not . toHaveFocus ( ) ;
340
+ }
341
+ ) ;
324
342
} ) ;
Original file line number Diff line number Diff line change @@ -44,8 +44,10 @@ function clickBooleanElement(element) {
44
44
function clickElement ( element ) {
45
45
fireEvent . mouseOver ( element ) ;
46
46
fireEvent . mouseMove ( element ) ;
47
- fireEvent . mouseDown ( element ) ;
48
- element . focus ( ) ;
47
+ const continueDefaultHandling = fireEvent . mouseDown ( element ) ;
48
+ if ( continueDefaultHandling ) {
49
+ element . focus ( ) ;
50
+ }
49
51
fireEvent . mouseUp ( element ) ;
50
52
fireEvent . click ( element ) ;
51
53
You can’t perform that action at this time.
0 commit comments