react-datetime-picker
react-datetime-picker copied to clipboard
isCalendarOpen Prop Ignored
Hi, Seems like the isCalendarOpen prop is not working.
Actual: When the calendar is forced to stay open via isCalendarOpen={true}, it is not opening.
Expected: When the prop isCalendarOpen={true} passed, it should force the calendar to stay open.
Thanks, Andrei.
For me the CalendarOpen prop somewhat works as long as the calendar is rendered while the value is set. In my App the Calendar is within a popup which is not rendered by default. The following code will open the calendar like expected. But if I set showStartDate to true from the get go it won't show.
There is also still the problem that clicking outside the open calendar will close it no matter the value of showStartDate. The only way to display again is to toggle the variable to false and back to true within a timeout function to allow react to do two re-renders. This of course leads to ugly flickering.
const [showStartDate, setShowStartDate] = useState(false);
[...]
<input
type="text"
id="searchDate"
onClick={() => {
setOpen( !open );
setShowStartDate(true);
}}
readOnly={true}
/>
[...]
<DateTimePicker
value={startDate}
isCalendarOpen={showStartDate}
minDate={new Date()}
onCalendarOpen={() => {
setShowStartDate(true);
setShowEndDate(false);
}}
onChange={date => {
setStartDate(date);
setShowStartDate(false);
setShowEndDate(true);
}}
/>
I think this might fix the issue but I don't have the time to test it right now.
DateTimePicker.jsx line 236
renderCalendar() {
let isCalendarOpen;
if(typeof(this.props.isCalendarOpen) !== "undefined"){
isCalendarOpen = this.props.isCalendarOpen;
} else {
isCalendarOpen = this.state.isCalendarOpen;
}
if (isCalendarOpen === null) {
return null;
}
This will give the prop isCalendarOpen priority over the built in open/close logik. If the prop isn't set the logic should work like it does right now.
Having this issue too.
This prop doesn't "hard-set" Calendar state, but rather allow to change it by changing this prop's value. I hear you that it's confusing and it will be fixed, but in future, breaking version.
This issue is stale because it has been open 90 days with no activity. Remove stale label or comment or this issue will be closed in 14 days.
This issue was closed because it has been stalled for 14 days with no activity.