Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions demo/src/Demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,17 @@ export default class Demo extends React.Component {
const randomMilliseconds = getRandomValue(0, Date.now())
this.setState({ selectedDate: moment(randomMilliseconds) })
}

render() {
return (
<div>
<div className="random-container">
<RaisedButton primary
<RaisedButton primary
label="Set random"
onClick={this.setRandomValue}
onClick={this.setRandomValue}
/>
</div>

<DateTimePicker
ref="picker"
className="datepicker"
Expand All @@ -45,7 +45,6 @@ export default class Demo extends React.Component {
floatingLabelText="Get my date"
format={this.state.format}
timePickerDelay={this.state.delay}
value={this.state.selectedDate}
onChange={selectedDate => this.setState({ selectedDate })}
/>

Expand Down
19 changes: 9 additions & 10 deletions src/DateTimePicker.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export default class DateTimePicker extends Component {
hideCalendarDate: PropTypes.bool,
firstDayOfWeek: PropTypes.number,
onDatePickerDismiss: PropTypes.func,
value: PropTypes.oneOfType([PropTypes.object, PropTypes.string, PropTypes.number]),
customValue: PropTypes.oneOfType([PropTypes.object, PropTypes.string, PropTypes.number]),
maxDate: PropTypes.oneOfType([PropTypes.object, PropTypes.string, PropTypes.number]),
minDate: PropTypes.oneOfType([PropTypes.object, PropTypes.string, PropTypes.number]),

Expand All @@ -66,7 +66,7 @@ export default class DateTimePicker extends Component {
}

static defaultProps = {
value: undefined,
customValue: undefined,
okLabel: 'OK',
minDate: undefined,
maxDate: undefined,
Expand Down Expand Up @@ -113,16 +113,16 @@ export default class DateTimePicker extends Component {
}

// eslint-disable-next-line
getInitialTime = () => this.props.value
? moment(this.props.value)
getInitialTime = () => this.props.customValue
? moment(this.props.customValue)
: null

state = {
dateTime: this.getInitialTime(),
}

componentDidUpdate = (prevProps) => {
if (prevProps.value !== this.props.value) {
if (prevProps.customValue !== this.props.customValue) {
this.setState({ dateTime: this.getInitialTime() });
}
}
Expand Down Expand Up @@ -221,8 +221,7 @@ export default class DateTimePicker extends Component {
onDateSelected,
onTimeSelected,
disabled,
placeholder,
value,
customValue,
...other
} = this.props;

Expand All @@ -232,21 +231,21 @@ export default class DateTimePicker extends Component {
onFocus={this.handleFocus}
className={textFieldClassName}
onClick={this.openDatePicker}
value={value ? this.getDisplayTime() : placeholder}
value={this.getDisplayTime()}
style={{ ...styles.textField, ...textFieldStyle }}
disabled={disabled}
{...other}
/>

{
clearIcon
? <IconButton
? <IconButton
onClick={this.clearState}
style={{ ...styles.clearIcon, ...clearIconStyle }}
disabled={disabled}>
{ clearIcon }
</IconButton>
: null
: null
}

<DatePicker
Expand Down