File tree 2 files changed +34
-2
lines changed
2 files changed +34
-2
lines changed Original file line number Diff line number Diff line change @@ -1460,6 +1460,38 @@ describe('getInputProps', () => {
1460
1460
} ) ,
1461
1461
)
1462
1462
} )
1463
+
1464
+ test ( 'the open menu will be closed and highlighted item will not be selected if the blur event related target is null' , ( ) => {
1465
+ const stateReducer = jest . fn ( ) . mockImplementation ( s => s )
1466
+ const { container} = renderCombobox ( {
1467
+ isOpen : true ,
1468
+ highlightedIndex : 0 ,
1469
+ stateReducer,
1470
+ } )
1471
+ const input = getInput ( )
1472
+ document . body . appendChild ( container )
1473
+
1474
+ fireEvent . blur ( input , { relatedTarget : null } )
1475
+
1476
+ expect ( stateReducer ) . toHaveBeenCalledTimes ( 1 )
1477
+ expect ( stateReducer ) . toHaveBeenCalledWith (
1478
+ {
1479
+ highlightedIndex : 0 ,
1480
+ inputValue : '' ,
1481
+ isOpen : true ,
1482
+ selectedItem : null ,
1483
+ } ,
1484
+ expect . objectContaining ( {
1485
+ type : stateChangeTypes . InputBlur ,
1486
+ changes : {
1487
+ highlightedIndex : - 1 ,
1488
+ inputValue : '' ,
1489
+ isOpen : false ,
1490
+ selectedItem : null ,
1491
+ } ,
1492
+ } ) ,
1493
+ )
1494
+ } )
1463
1495
} )
1464
1496
1465
1497
describe ( 'on focus' , ( ) => {
Original file line number Diff line number Diff line change @@ -416,15 +416,15 @@ function useCombobox(userProps = {}) {
416
416
: event . target . value ,
417
417
} )
418
418
}
419
- const inputHandleBlur = ( ) => {
419
+ const inputHandleBlur = event => {
420
420
/* istanbul ignore else */
421
421
if (
422
422
latestState . isOpen &&
423
423
! mouseAndTouchTrackersRef . current . isMouseDown
424
424
) {
425
425
dispatch ( {
426
426
type : stateChangeTypes . InputBlur ,
427
- selectItem : true ,
427
+ selectItem : event . relatedTarget !== null ,
428
428
} )
429
429
}
430
430
}
You can’t perform that action at this time.
0 commit comments