Skip to content
This repository has been archived by the owner on Jun 28, 2021. It is now read-only.

fixes textfield not being updated if it received dynamically a value #79

Merged
merged 1 commit into from
Oct 18, 2015

Conversation

tleunen
Copy link
Owner

@tleunen tleunen commented Oct 15, 2015

Related to #58.

If the textfield receives dynamically a value, without directly through the input from a user, the textfield wasn't updated properly (the floating label/css classes were not updated).
By forcing to change the value with the MDL upstream change function, it resolves the issue.

@faergeek
Copy link
Contributor

Still to avoid setting value twice we should not pass argument to change method.

@tleunen
Copy link
Owner Author

tleunen commented Oct 17, 2015

So I updated the code to only force a change value on the textfields that are not focused.
What do you think?

@faergeek
Copy link
Contributor

I don't think we need these checks actually :-) Just leaving it with no argument will be ok.

Take a look at these lines https://github.com/tleunen/react-mdl/blob/master/extra/material.js#L2637-L2639

So if we don't pass a value it just updates classes.
And as classList is used everywhere we won't have any actual changes when they're not needed and no performance problems.
Take a look at this video for explanation why http://www.youtube.com/watch?v=hZJacl2VkKo

@faergeek
Copy link
Contributor

Even better, upstream code checks if there's need to add/remove classes, so even classList is not touched.

@tleunen
Copy link
Owner Author

tleunen commented Oct 18, 2015

Yes, it would work, but only with the current version that we have in react-mdl. Upstream, the code has changed to fix an issue and now it supports to pass an empty string.
https://github.com/google/material-design-lite/blob/master/src/textfield/textfield.js#L201-L205

@faergeek
Copy link
Contributor

Even with that in mind I don't that we should use contains to detect if it's focused, it's better to use ref and just check equality then :-)

But don't close this yet, I'd like to test if setting value twice will have any impact on performance.

@tleunen
Copy link
Owner Author

tleunen commented Oct 18, 2015

👍 used ref instead to avoid searching inside the entire element.

tleunen added a commit that referenced this pull request Oct 18, 2015
fixes textfield not being updated if it received dynamically a value
@tleunen tleunen merged commit 009e700 into master Oct 18, 2015
@tleunen tleunen deleted the textfield-dynamic-value branch October 18, 2015 21:18
@faergeek
Copy link
Contributor

Could you publish that to npm before we introduce breaking changes?

@tleunen
Copy link
Owner Author

tleunen commented Oct 19, 2015

There are already too many changes and breaking changes, so I was planning to finish them before releasing a new version

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

Successfully merging this pull request may close these issues.

2 participants