File tree 3 files changed +31
-5
lines changed
packages/react-select/src
3 files changed +31
-5
lines changed Original file line number Diff line number Diff line change
1
+ ---
2
+ ' react-select ' : patch
3
+ ---
4
+
5
+ No longer send pop-value action when multi-select is empty. This correctly resolves typings with that event, where removedValue cannot be undefined.
Original file line number Diff line number Diff line change @@ -1096,10 +1096,12 @@ export default class Select<
1096
1096
newValueArray [ 0 ] || null
1097
1097
) ;
1098
1098
1099
- this . onChange ( newValue , {
1100
- action : 'pop-value' ,
1101
- removedValue : lastSelectedValue ,
1102
- } ) ;
1099
+ if ( lastSelectedValue ) {
1100
+ this . onChange ( newValue , {
1101
+ action : 'pop-value' ,
1102
+ removedValue : lastSelectedValue ,
1103
+ } ) ;
1104
+ }
1103
1105
} ;
1104
1106
1105
1107
// ==============================
Original file line number Diff line number Diff line change @@ -1906,6 +1906,7 @@ test('should call onChange with an array on hitting backspace when backspaceRemo
1906
1906
isClearable
1907
1907
isMulti
1908
1908
onChange = { onChangeSpy }
1909
+ value = { [ OPTIONS [ 0 ] ] }
1909
1910
/>
1910
1911
) ;
1911
1912
fireEvent . keyDown ( container . querySelector ( '.react-select__control' ) ! , {
@@ -1915,10 +1916,28 @@ test('should call onChange with an array on hitting backspace when backspaceRemo
1915
1916
expect ( onChangeSpy ) . toHaveBeenCalledWith ( [ ] , {
1916
1917
action : 'pop-value' ,
1917
1918
name : 'test-input-name' ,
1918
- removedValue : undefined ,
1919
+ removedValue : OPTIONS [ 0 ] ,
1919
1920
} ) ;
1920
1921
} ) ;
1921
1922
1923
+ test ( 'should call not call onChange on hitting backspace when backspaceRemovesValue is true and isMulti is true and there are no values' , ( ) => {
1924
+ let onChangeSpy = jest . fn ( ) ;
1925
+ let { container } = render (
1926
+ < Select
1927
+ { ...BASIC_PROPS }
1928
+ backspaceRemovesValue
1929
+ isClearable
1930
+ isMulti
1931
+ onChange = { onChangeSpy }
1932
+ />
1933
+ ) ;
1934
+ fireEvent . keyDown ( container . querySelector ( '.react-select__control' ) ! , {
1935
+ keyCode : 8 ,
1936
+ key : 'Backspace' ,
1937
+ } ) ;
1938
+ expect ( onChangeSpy ) . not . toHaveBeenCalled ( ) ;
1939
+ } ) ;
1940
+
1922
1941
test ( 'multi select > clicking on X next to option will call onChange with all options other that the clicked option' , ( ) => {
1923
1942
let onChangeSpy = jest . fn ( ) ;
1924
1943
let { container } = render (
You can’t perform that action at this time.
0 commit comments