File tree Expand file tree Collapse file tree 3 files changed +31
-5
lines changed
packages/react-select/src Expand file tree Collapse file tree 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<
10961096 newValueArray [ 0 ] || null
10971097 ) ;
10981098
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+ }
11031105 } ;
11041106
11051107 // ==============================
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
19061906 isClearable
19071907 isMulti
19081908 onChange = { onChangeSpy }
1909+ value = { [ OPTIONS [ 0 ] ] }
19091910 />
19101911 ) ;
19111912 fireEvent . keyDown ( container . querySelector ( '.react-select__control' ) ! , {
@@ -1915,10 +1916,28 @@ test('should call onChange with an array on hitting backspace when backspaceRemo
19151916 expect ( onChangeSpy ) . toHaveBeenCalledWith ( [ ] , {
19161917 action : 'pop-value' ,
19171918 name : 'test-input-name' ,
1918- removedValue : undefined ,
1919+ removedValue : OPTIONS [ 0 ] ,
19191920 } ) ;
19201921} ) ;
19211922
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+
19221941test ( 'multi select > clicking on X next to option will call onChange with all options other that the clicked option' , ( ) => {
19231942 let onChangeSpy = jest . fn ( ) ;
19241943 let { container } = render (
You can’t perform that action at this time.
0 commit comments