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(text-field): remove foundation.setValue call during onChange #350

Merged
merged 22 commits into from
Oct 29, 2018

Conversation

moog16
Copy link

@moog16 moog16 commented Oct 17, 2018

fixes #333

By removing the componentDidUpdate from the index.js file, we no longer call foundation.setValue every input change. MDC Web was not doing this, so this is the correct fix.

@codecov-io
Copy link

codecov-io commented Oct 17, 2018

Codecov Report

Merging #350 into master will decrease coverage by 0.11%.
The diff coverage is 95%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #350      +/-   ##
==========================================
- Coverage   96.97%   96.86%   -0.12%     
==========================================
  Files          51       51              
  Lines        1816     1816              
  Branches      209      210       +1     
==========================================
- Hits         1761     1759       -2     
- Misses         55       57       +2
Impacted Files Coverage Δ
packages/text-field/index.js 100% <100%> (ø) ⬆️
packages/text-field/Input.js 95% <93.33%> (-2.41%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e96ca10...2c1aa49. Read the comment docs.

@@ -262,7 +263,7 @@ class TextField extends React.Component {
key='text-field-container'
>
{leadingIcon ? this.renderIcon(leadingIcon) : null}
{this.renderInput()}
{this.foundation_ ? this.renderInput() : null}
Copy link
Author

Choose a reason for hiding this comment

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

This actually fixes #303


// this should be in the componentDidMount, but foundation is not created
// at that time.
if (value && foundation !== prevProps.foundation) {
Copy link
Author

Choose a reason for hiding this comment

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

Once this #353 is fixed, I will move this back into componentDidMount

this.inputElement = React.createRef();
}
inputElement = React.createRef();
state = {disableProgramaticSetValue: false};
Copy link
Contributor

Choose a reason for hiding this comment

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

Change this to enableProgrammaticSetValue, it's easier to reason about logic if the variable is positive

foundation.autoCompleteFocus();
this.setState({disableProgramaticSetValue: true});
Copy link
Contributor

Choose a reason for hiding this comment

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

So the onChange event is only emitted when it's from a user? Do programmatic changes emit any event?

Copy link
Author

Choose a reason for hiding this comment

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

Right the onChange event is only triggered when a user types. BOTH events (user and programatic) trigger updates props, which calls componentDidUpdate.

if (!this.state.disableProgramaticSetValue) {
foundation.setValue(value);
} else {
this.setState({disableProgramaticSetValue: false});
Copy link
Contributor

@bonniezhou bonniezhou Oct 22, 2018

Choose a reason for hiding this comment

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

at what point does the Text Field's state.value get updated if the change is from a user? should we be calling handleValueChange in handleBlur?

Copy link
Author

Choose a reason for hiding this comment

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

we call setValue in handleBlur, but its called within MDC's foundation.deactivateFocus

@moog16
Copy link
Author

moog16 commented Oct 25, 2018

update - ready for re-review

Copy link
Contributor

@bonniezhou bonniezhou left a comment

Choose a reason for hiding this comment

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

LGTM aside from one typo

// this should be in the componentDidMount, but foundation is not created
// at that time.
// Will fix this in
// https://github.com/material-components/material-components-web-react/pull/350/files
Copy link
Contributor

Choose a reason for hiding this comment

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

should be 353, not 350

@moog16 moog16 merged commit 36469f7 into master Oct 29, 2018
@moog16 moog16 deleted the fix/text-field/validation-handling branch October 29, 2018 18:21
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.

3 participants