question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Not closing the calendar on selection of a date

See original GitHub issue

The calendar is not hidden when a calendar date is selected. No errors or warnings are placed into the console. React Calendar V 0.53.0

<DatePicker
            className={"date-field" + (className ? " " + className : "") + (error ? " error" : "")}
            selected={date}
            onChange={(newValue) => onChange(identifier, newValue)}
            dateFormat="DD/MM/YYYY"
        />

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:5
  • Comments:15 (3 by maintainers)

github_iconTop GitHub Comments

36reactions
honzajerabekcommented, Nov 15, 2017

adding <label onClick={e => e.preventDefault()}><DatePicker .... /></label> fixed this issue for me. In debugger I found that after select, setOpen(false) was called and DatePicker was closed but right after that it was reopened again (by label? 🤔)

edit: I’m using semantic-ui-react that has their own implementation of label behavior, but you have the idea…

19reactions
giorgosavgeriscommented, Jul 26, 2019

If the datepicker remains open because it is wrapped inside label, you can call preventDefault on onChange.

import React from 'react';
import DatePicker from 'react-datepicker';

class MyDatepicker extends React.Component {
  handleChange = (date, e) => {
    if (e && typeof e.preventDefault === 'function') {
      e.preventDefault();
    }

    const {onChange} = this.props;

    if (onChange) {
      onChange(date);
    }
  };

  render() {
    return (
      <DatePicker
          {...this.props}
         onChange={this.handleChange}
      />
    );
  }
}
...
Read more comments on GitHub >

github_iconTop Results From Across the Web

React-datepicker | Calendar not closing on selection of date
Recently I picked up a project that uses react-datepicker and there's an issue where the calendar just isn't closing on selection of a...
Read more >
Datepicker not closing after selection - Chrome - OutSystems
I have some logic built into my Datepicker which requires me to refresh the date selections when a From or To Date is...
Read more >
DatePicker / How To / Prevent the Popup Close - React
To prevent the DatePicker popup from closing, use the preventDefault method. The following example demonstrates how to prevent the popup from closing.
Read more >
React Multi Date Picker - Events
a simple React datepicker component for working with gregorian, persian, arabic and indian calendars with the ability to select the date in single, ......
Read more >
react-datetime - npm
It is possible to disable dates in the calendar if the user are not allowed to select them, e.g. dates in the past....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found