static-cms/src/components/Widgets/DateTimeControl.js
Cássio Zen 782c386d3e Widget should set default values through onChange
Otherwise, default value may not get persisted
2016-12-01 16:28:33 -02:00

24 lines
543 B
JavaScript

import React, { PropTypes } from 'react';
import DateTime from 'react-datetime';
export default class DateTimeControl extends React.Component {
componentDidMount() {
if (!this.props.value) {
this.props.onChange(new Date());
}
}
handleChange = (datetime) => {
this.props.onChange(datetime);
};
render() {
return <DateTime value={this.props.value} onChange={this.handleChange} />;
}
}
DateTimeControl.propTypes = {
onChange: PropTypes.func.isRequired,
value: PropTypes.object, // eslint-disable-line
};