@@ -542,14 +542,15 @@ describe('Rendering', () => {
542
542
it (
543
543
'should close the Combobox when the input is blurred' ,
544
544
suppressConsoleLogs ( async ( ) => {
545
+ let closeHandler = jest . fn ( )
545
546
let data = [
546
547
{ id : 1 , name : 'alice' , label : 'Alice' } ,
547
548
{ id : 2 , name : 'bob' , label : 'Bob' } ,
548
549
{ id : 3 , name : 'charlie' , label : 'Charlie' } ,
549
550
]
550
551
551
552
render (
552
- < Combobox < ( typeof data ) [ number ] > name = "assignee" by = "id" >
553
+ < Combobox < ( typeof data ) [ number ] > name = "assignee" by = "id" onClose = { closeHandler } >
553
554
< Combobox . Input onChange = { NOOP } />
554
555
< Combobox . Button />
555
556
< Combobox . Options >
@@ -569,7 +570,9 @@ describe('Rendering', () => {
569
570
assertComboboxList ( { state : ComboboxState . Visible } )
570
571
571
572
// Close the combobox
573
+ expect ( closeHandler ) . toHaveBeenCalledTimes ( 0 )
572
574
await blur ( getComboboxInput ( ) )
575
+ expect ( closeHandler ) . toHaveBeenCalledTimes ( 1 )
573
576
574
577
// Verify it is closed
575
578
assertComboboxList ( { state : ComboboxState . InvisibleUnmounted } )
@@ -2825,6 +2828,7 @@ describe.each([{ virtual: true }, { virtual: false }])(
2825
2828
'should be possible to close the combobox with Enter and choose the active combobox option' ,
2826
2829
suppressConsoleLogs ( async ( ) => {
2827
2830
let handleChange = jest . fn ( )
2831
+ let closeHandler = jest . fn ( )
2828
2832
2829
2833
function Example ( ) {
2830
2834
let [ value , setValue ] = useState < string | undefined > ( undefined )
@@ -2833,6 +2837,7 @@ describe.each([{ virtual: true }, { virtual: false }])(
2833
2837
< MyCombobox
2834
2838
comboboxProps = { {
2835
2839
value,
2840
+ onClose : closeHandler ,
2836
2841
onChange ( value : string | undefined ) {
2837
2842
setValue ( value )
2838
2843
handleChange ( value )
@@ -2861,7 +2866,9 @@ describe.each([{ virtual: true }, { virtual: false }])(
2861
2866
await mouseMove ( options [ 0 ] )
2862
2867
2863
2868
// Choose option, and close combobox
2869
+ expect ( closeHandler ) . toHaveBeenCalledTimes ( 0 )
2864
2870
await press ( Keys . Enter )
2871
+ expect ( closeHandler ) . toHaveBeenCalledTimes ( 1 )
2865
2872
2866
2873
// Verify it is closed
2867
2874
assertComboboxButton ( { state : ComboboxState . InvisibleUnmounted } )
@@ -4883,15 +4890,18 @@ describe.each([{ virtual: true }, { virtual: false }])('Mouse interactions %s',
4883
4890
it (
4884
4891
'should be possible to click outside of the combobox which should close the combobox (even if we press the combobox button)' ,
4885
4892
suppressConsoleLogs ( async ( ) => {
4886
- render ( < MyCombobox /> )
4893
+ let closeHandler = jest . fn ( )
4894
+ render ( < MyCombobox comboboxProps = { { onClose : closeHandler } } /> )
4887
4895
4888
4896
// Open combobox
4889
4897
await click ( getComboboxButton ( ) )
4890
4898
assertComboboxList ( { state : ComboboxState . Visible } )
4891
4899
assertActiveElement ( getComboboxInput ( ) )
4892
4900
4893
4901
// Click the combobox button again
4902
+ expect ( closeHandler ) . toHaveBeenCalledTimes ( 0 )
4894
4903
await click ( getComboboxButton ( ) )
4904
+ expect ( closeHandler ) . toHaveBeenCalledTimes ( 1 )
4895
4905
4896
4906
// Should be closed now
4897
4907
assertComboboxList ( { state : ComboboxState . InvisibleUnmounted } )
0 commit comments