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

[Input] should accommodate number and string values #7791

Merged
merged 5 commits into from Aug 17, 2017

Conversation

rosskevin
Copy link
Member

@rosskevin rosskevin commented Aug 16, 2017

The previous isControlled() was too naive and not in-line with the definition of a controlled component as defined by React. This previous implementation was the root cause of failures to trigger the dirty state on the field.

  • PR has tests / docs demo, and is linted.
  • Commit and PR titles begin with [ComponentName], and are in imperative form: "[Component] Fix leaky abstraction".
  • Description explains the issue / use-case resolved, and auto-closes the related issue(s) (http://tr.im/vFqem).

@rosskevin rosskevin added bug 🐛 Something doesn't work v1 labels Aug 16, 2017
@rosskevin
Copy link
Member Author

This works and doesn't break anything, but I need to do a bit more with isDirty to accommodate numbers.

@rosskevin rosskevin changed the title [Input] isControlled() should accommodate number and string values WIP [Input] isControlled() should accommodate number and string values Aug 17, 2017
… numbers

This is based on the previous implementation, still not sure that 0 !isDirty
@rosskevin rosskevin changed the title WIP [Input] isControlled() should accommodate number and string values [Input] isControlled() should accommodate number and string values Aug 17, 2017
@rosskevin
Copy link
Member Author

rosskevin commented Aug 17, 2017

Ok, this is good to review. In order to track the details, I've tried to be as explicit as possible with documentation and tests.

The issues were two fold:

  1. isControlled check was too naive
  2. isDirty check (that determines if the label is presented as placeholder or above the field) did not accommodate zero values.

@rosskevin rosskevin changed the title [Input] isControlled() should accommodate number and string values [Input] should accommodate number and string values Aug 17, 2017
@rosskevin
Copy link
Member Author

BTW - I have tested it locally on docs and my own number field.

isControlled() {
return typeof this.props.value === 'string';
const { onChange, value } = this.props;
Copy link
Member

Choose a reason for hiding this comment

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

onChange shouldn't be taken into account. React isn't using it for native components.

}

/**
* Determine if field is dirty (a.k.a. filled).
Copy link
Member

Choose a reason for hiding this comment

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

The master branch was looking for invalid values instead of valid ones. Have you considered this option https://github.com/callemall/material-ui/blob/master/src/TextField/TextField.js#L110 ? Maybe we could make the implementation shorter/simpler.

@oliviertassinari oliviertassinari added the component: text field This is the name of the generic UI component, not the React module! label Aug 17, 2017
@rosskevin
Copy link
Member Author

Refactored with logic from master

@rosskevin rosskevin merged commit 9a6a3dd into mui:v1-beta Aug 17, 2017
@rosskevin rosskevin deleted the input-controlled-condition branch August 17, 2017 14:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 Something doesn't work component: text field This is the name of the generic UI component, not the React module!
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants