Skip to content

Commit

Permalink
fix(ComboBox): fix lost change in state (#5784)
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 #5623.
  • Loading branch information
asudoh authored Apr 2, 2020
1 parent c75464f commit e05213a
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 e05213a

Please sign in to comment.