Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(Dropdown): fix deepEqual bug #3104

Merged
merged 4 commits into from
Sep 10, 2018
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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