File tree 3 files changed +20
-8
lines changed
3 files changed +20
-8
lines changed Original file line number Diff line number Diff line change @@ -266,13 +266,6 @@ function mousedownDefaultBehavior({
266
266
node ?: Node
267
267
offset ?: number
268
268
} ) {
269
- // The closest focusable element is focused when a `mousedown` would have been fired.
270
- // Even if there was no `mousedown` because the element was disabled.
271
- // A `mousedown` that preventsDefault cancels this though.
272
- focus ( target )
273
-
274
- // TODO: What happens if a focus event handler interfers?
275
-
276
269
// An unprevented mousedown moves the cursor to the closest character.
277
270
// We try to approximate the behavior for a no-layout environment.
278
271
if ( ! targetIsDisabled ) {
@@ -326,6 +319,11 @@ function mousedownDefaultBehavior({
326
319
selection . addRange ( range . cloneRange ( ) )
327
320
}
328
321
}
322
+
323
+ // The closest focusable element is focused when a `mousedown` would have been fired.
324
+ // Even if there was no `mousedown` because the element was disabled.
325
+ // A `mousedown` that preventsDefault cancels this though.
326
+ focus ( target )
329
327
}
330
328
331
329
function getTextRange (
Original file line number Diff line number Diff line change @@ -368,3 +368,17 @@ describe('focus control when clicking label', () => {
368
368
expect ( input ) . not . toHaveFocus ( )
369
369
} )
370
370
} )
371
+
372
+ test ( 'focus event handler can override selection' , async ( ) => {
373
+ const { element, user} = setup ( `<input value="hello"/>` , {
374
+ focus : false ,
375
+ } )
376
+ element . addEventListener ( 'focus' , e =>
377
+ ( e . target as HTMLInputElement ) . select ( ) ,
378
+ )
379
+
380
+ await user . click ( element )
381
+
382
+ expect ( element ) . toHaveProperty ( 'selectionStart' , 0 )
383
+ expect ( element ) . toHaveProperty ( 'selectionEnd' , 5 )
384
+ } )
Original file line number Diff line number Diff line change @@ -19,9 +19,9 @@ test('type into input', async () => {
19
19
input[value="foo"] - mousemove
20
20
input[value="foo"] - pointerdown
21
21
input[value="foo"] - mousedown: primary
22
+ input[value="foo"] - select
22
23
input[value="foo"] - focus
23
24
input[value="foo"] - focusin
24
- input[value="foo"] - select
25
25
input[value="foo"] - pointerup
26
26
input[value="foo"] - mouseup: primary
27
27
input[value="foo"] - click: primary
You can’t perform that action at this time.
0 commit comments