force date when it's out of range

old
@soyjavi 2015-11-17 00:02:32 +07:00
parent 0cacdf14ec
commit 20d8834ccb
1 changed files with 5 additions and 6 deletions

View File

@ -21,14 +21,13 @@ class CalendarDialog extends React.Component {
state = {
date: this.props.value,
display: 'months',
year: this.props.value.getFullYear()
display: 'months'
};
handleCalendarChange = (value) => {
const state = {display: 'months', year: value.getFullYear()};
if (!time.dateOutOfRange(value, this.props.minDate, this.props.maxDate)) {
state.date = value;
const state = {display: 'months', date: value};
if (time.dateOutOfRange(value, this.props.minDate, this.props.maxDate)) {
state.date = this.props.maxDate || this.props.minDate;
}
this.setState(state);
};
@ -61,7 +60,7 @@ class CalendarDialog extends React.Component {
<span className={style.day}>{this.state.date.getDate()}</span>
</div>
<span className={style.year} onClick={this.handleSwitchDisplay.bind(this, 'years')}>
{this.state.year}
{this.state.date.getFullYear()}
</span>
</header>