Skip to content

Commit 98aad8d

Browse files
authored
Merge branch 'master' into aria-describedby-option
2 parents 3344a08 + a8b8f43 commit 98aad8d

File tree

4 files changed

+33
-6
lines changed

4 files changed

+33
-6
lines changed

packages/react-select/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# react-select
22

3+
## 5.8.1
4+
5+
### Patch Changes
6+
7+
- [`dd740ced`](https://github.com/JedWatson/react-select/commit/dd740cedb29c810a89da4445d4864cd7e63d3aaf) [#5960](https://github.com/JedWatson/react-select/pull/5960) Thanks [@leonaves](https://github.com/leonaves)! - No longer send pop-value action when multi-select is empty. This correctly resolves typings with that event, where removedValue cannot be undefined.
8+
39
## 5.8.0
410

511
### Minor Changes

packages/react-select/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-select",
3-
"version": "5.8.0",
3+
"version": "5.8.1",
44
"description": "A Select control built with and for ReactJS",
55
"main": "dist/react-select.cjs.js",
66
"module": "dist/react-select.esm.js",

packages/react-select/src/Select.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1098,10 +1098,12 @@ export default class Select<
10981098
newValueArray[0] || null
10991099
);
11001100

1101-
this.onChange(newValue, {
1102-
action: 'pop-value',
1103-
removedValue: lastSelectedValue,
1104-
});
1101+
if (lastSelectedValue) {
1102+
this.onChange(newValue, {
1103+
action: 'pop-value',
1104+
removedValue: lastSelectedValue,
1105+
});
1106+
}
11051107
};
11061108

11071109
// ==============================

packages/react-select/src/__tests__/Select.test.tsx

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff 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+
19221941
test('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(

0 commit comments

Comments
 (0)