Skip to content

Commit

Permalink
fix(ComboBox): fix lost change in state
Browse files Browse the repository at this point in the history
This change brings back the change detection logic of `selectedItems`
that was lost by moving away from `componentWillReceiveProps()`.

Fixes carbon-design-system#5623.
  • Loading branch information
asudoh committed Apr 2, 2020
1 parent 9c1896a commit 1b284a7
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion packages/react/src/components/ComboBox/ComboBox.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 1b284a7

Please sign in to comment.