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 allowClear option [Closes #63] #65

Merged
merged 2 commits into from
Feb 28, 2017
Merged

Conversation

jordanbyron
Copy link
Contributor

When the allowClear option is enabled and that same component has a onChange callback, clicking the clear icon will cause an infinite loop. The root cause seems to be thatthis.el.val() returns null when previously set to an empty string, which is what happens when the input is cleared. As expected shallowEqualFuzzy returns false when comparing null to '' which causes an infinite onChange callback loop.

The new fuzzyValuesEqual method returns true when currentValue is null and newValue is equal to an empty string, otherwise it calls shallowEqualFuzzy which was the previous behavior.

I've also updated the examples with a select2 component set to allowClear which can be used to manually test the new behavior. Let me know if there is anything you'd like me to change. Thanks! 😄

`this.el.val()` returns +null+ when previously set to and empty string,
and `shallowEqualFuzzy` returns false when comparing null to '' which
causes an infinite onChange callback loop.

The new `fuzzyValuesEqual` method returns +true+ when `currentValue` is
+null+ and `newValue` is equal to an empty string, otherwise it calls
`shallowEqualFuzzy` which was the previous behavior.
@@ -287,6 +294,28 @@ export default class Tags extends Component {
);
}

example11() {
const { value11, data11, onChange11 } = this.state;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

onChange11 is not defined

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please fix style issues (eslint)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All set!

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@rkit
Copy link
Owner

rkit commented Feb 28, 2017

Thanks!

@rkit rkit closed this Feb 28, 2017
@rkit rkit reopened this Feb 28, 2017
@rkit rkit merged commit 281c339 into rkit:master Feb 28, 2017
@rkit
Copy link
Owner

rkit commented Feb 28, 2017

I released a new beta version 1.0.4-beta3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants