From e05213a390d4493dbffd92ec14ab773b205d4b0a Mon Sep 17 00:00:00 2001 From: Akira Sudoh Date: Fri, 3 Apr 2020 08:41:53 +0900 Subject: [PATCH] fix(ComboBox): fix lost change in state (#5784) This change brings back the change detection logic of `selectedItems` that was lost by moving away from `componentWillReceiveProps()`. Fixes #5623. --- packages/react/src/components/ComboBox/ComboBox.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/packages/react/src/components/ComboBox/ComboBox.js b/packages/react/src/components/ComboBox/ComboBox.js index 253f19ac76e2..3dc78259600c 100644 --- a/packages/react/src/components/ComboBox/ComboBox.js +++ b/packages/react/src/components/ComboBox/ComboBox.js @@ -188,7 +188,16 @@ export default class ComboBox extends React.Component { }; static getDerivedStateFromProps(nextProps, state) { - return { inputValue: getInputValue(nextProps, state) }; + const { prevSelectedItem, doneInitialSelectedItem } = state; + const { selectedItem } = nextProps; + if (!doneInitialSelectedItem || prevSelectedItem !== selectedItem) { + return { + doneInitialSelectedItem: true, + prevSelectedItem: selectedItem, + inputValue: getInputValue(nextProps, state), + }; + } + return null; } constructor(props) {