You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
React does not allow setting null as value on an input field to clear the input value. For controlled components, the value should be set as an empty string. However, DatePicker does not allow value to be set to a string and instead expects an Date object.
Steps to reproduce
Setup DatePicker as a controlled component and set a value's default to an empty string.
Future versions of React will treat as a request to clear the input. However, React 0.14 has been ignoring value={null}. React 15 warns you on a null input value and offers you to clarify your intention. To fix the warning, you may explicitly pass an empty string to clear a controlled input, or pass undefined to make the input uncontrolled. @antoaravinth in #5048
The text was updated successfully, but these errors were encountered:
getControlledDate(props = this.props) {
if (props.value instanceof Date) {
return props.value;
} elseif (props.value == null || props.value == undefined) { // IDK if these are the ideal checks
return props.defaultDate;
}
}
would probably resolve this? Would ensure that when the value is reset it will default back to the original default date. Additionally, the developer still has control over the reset value (As opposed to returning PropTypes.object).
For the controlled date component, if the date value is null at the start use empty object {} instead of string to avoid react and material UI warning/error
oliviertassinari
changed the title
Setting DatePicker to a default state as a controlled component
[DatePicker] Setting to a default state as a controlled component
Dec 18, 2016
Problem description
React does not allow setting null as value on an input field to clear the input value. For controlled components, the value should be set as an empty string. However, DatePicker does not allow value to be set to a string and instead expects an Date object.
Steps to reproduce
Setup DatePicker as a controlled component and set a value's default to an empty string.
Versions
https://facebook.github.io/react/blog/2016/04/07/react-v15.html
The text was updated successfully, but these errors were encountered: