react-datetime-picker icon indicating copy to clipboard operation
react-datetime-picker copied to clipboard

isCalendarOpen Prop Ignored

Open andreifg1 opened this issue 5 years ago • 4 comments

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.

andreifg1 avatar Jun 03 '19 07:06 andreifg1

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);
        }}
      />

CapsE avatar Jun 11 '19 13:06 CapsE

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.

CapsE avatar Jun 14 '19 09:06 CapsE

Having this issue too.

lr001dev avatar Jul 29 '20 22:07 lr001dev

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.

wojtekmaj avatar Jul 31 '20 18:07 wojtekmaj

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.

github-actions[bot] avatar Jan 23 '23 00:01 github-actions[bot]

This issue was closed because it has been stalled for 14 days with no activity.

github-actions[bot] avatar Feb 06 '23 00:02 github-actions[bot]