Skip to content

Commit

Permalink
fix(Dropdown): fix deepEqual bug (#3104)
Browse files Browse the repository at this point in the history
* Fix dropdown deep equal bug

* docs(Dropdown): link issue to fix
  • Loading branch information
pedromtorres authored and levithomason committed Sep 10, 2018
1 parent bf8adb8 commit f04d218
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/modules/Dropdown/Dropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,12 @@ export default class Dropdown extends Component {
this.setSelectedIndex(nextProps.value)
}

if (!_.isEqual(nextProps.options, this.props.options)) {
// The selected index is only dependent on option keys/values.
// We only check those properties to avoid recursive performance impacts.
// https://github.com/Semantic-Org/Semantic-UI-React/issues/3000
if (
!_.isEqual(this.getKeyAndValues(nextProps.options), this.getKeyAndValues(this.props.options))
) {
this.setSelectedIndex(undefined, nextProps.options)
}
}
Expand Down Expand Up @@ -787,6 +792,9 @@ export default class Dropdown extends Component {
// Getters
// ----------------------------------------

getKeyAndValues = options =>
(options ? options.map(option => _.pick(option, ['key', 'value'])) : options)

// There are times when we need to calculate the options based on a value
// that hasn't yet been persisted to state.
getMenuOptions = (value = this.state.value, options = this.props.options) => {
Expand Down

0 comments on commit f04d218

Please sign in to comment.