calendar
calendar copied to clipboard
RangeCalendar, How can i set initial panels without initial values
Here is a scence: when we use dateRangePicker, we disabled furture date, and did not set initial values, but the panel show current month and next month. how can i change panel to prev month and current month
I'd like to know this too.
I'm now using an ugly workaround that sets a start date in the previous month when opening the calendar, and shortly after changes it back to the correct value. Relevant section:
onStartOpenChange(open) {
if (open && this.state.start.format("MYYYY") === moment().format("MYYYY")) {
const dummyStart = this.state.start.clone().startOf("month").subtract(1, "day"),
startFixer = function() {
const f = function() {
this.setState({ dummyStart: null });
};
setTimeout(f.bind(this), 50);
};
this.setState({ open: true, dummyStart: dummyStart }, startFixer.bind(this));
} else {
this.setState({ open });
}
}
render() {
const calendar = (
<RangeCalendar
onSelect={this.dateSelected}
showWeekNumber={false}
defaultValue={[this.start, this.end]}
locale={enUS}
showOk={false}
showDateInput={false}
showToday={false}
showClear={false}
disabledDate={disabledAfterToday}
/>
);
return (
<div className="picker-component">
<Picker
onOpenChange={this.onStartOpenChange.bind(this)}
value={[this.state.dummyStart || this.state.start, this.state.end]}
animation="slide-up"
calendar={calendar}
open={this.state.open}
>
{() => {
return (<button className="button primary"></button>);
}}
</Picker>
</div>
);
}
It's for when the initial values are both in the current month, but I think that is the same case as with the default values (today).