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

Allow using DatePicker as a controlled input #1170

Merged
merged 4 commits into from
Jul 16, 2015
Merged

Conversation

marnusw
Copy link
Contributor

@marnusw marnusw commented Jul 15, 2015

There were two problems preventing controlled DatePicker inputs:

  1. The underlying TextField threw an error because the DatePicker would always setValue() and this is not allowed on controlled inputs.
  2. The date value wasn't formatted when rendering, only upon setting the TextField value.

Both items are fixed here, along with some additional documentation on controlled DatePickers.

this.refs.input.setValue(this.props.formatDate(d));
if (!this.refs.input._isControlled()) {
this.refs.input.setValue(this.props.formatDate(d));
}
Copy link
Member

Choose a reason for hiding this comment

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

We use this naming convention to indicate that _isControlled() is private to the component. Since we're passing all the props to the TextField input anyways, you should be able to determine this based on the props being passed in to date picker.

@marnusw
Copy link
Contributor Author

marnusw commented Jul 16, 2015

I've fixed it. I was cheating to avoid duplicating the method, but I'll adhere to the convention strictly from now on. Thanks for the feedback @hai-cea.

@hai-cea
Copy link
Member

hai-cea commented Jul 16, 2015

Thanks @marnusw!

hai-cea pushed a commit that referenced this pull request Jul 16, 2015
Allow using DatePicker as a controlled input
@hai-cea hai-cea merged commit 5e112a4 into mui:master Jul 16, 2015
@zannager zannager added component: date picker This is the name of the generic UI component, not the React module! component: pickers This is the name of the generic UI component, not the React module! labels Mar 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: date picker This is the name of the generic UI component, not the React module! component: pickers 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.

3 participants