title: Calling a function when the datepicker closes, when I click only outside of the datepicker
body: <p>Is it possible to set the datepicker to close only when I click outside the datepicker? When closing the calendar, if the date was selected, the <code>alertDate</code> function was called?</p>
  
  <p>Code here: <a href="https://stackblitz.com/edit/react-o8dm7y" rel="nofollow noreferrer">https://stackblitz.com/edit/react-o8dm7y</a></p>
  
  <pre><code>class App extends Component {
    constructor() {
      super();
      this.state = {
        selectedDate: '',
        arrayDates: []
      };
    }
  
    handleChangeDate = (date) =&gt; {
      let newArrayDates = [...this.state.arrayDates]
      newArrayDates.push(date)
  
      this.setState({
        selectedDate: date,
        arrayDates: newArrayDates
      })
    }
  
    alertDate = () =&gt; {
      console.log(this.state.selectedDate)
    }
  
    render() {
      console.log(this.state.arrayDates)
      return (
        &lt;div&gt;
           &lt;DatePicker
              selected={this.state.selectedDate}
              onChange={this.handleChangeDate}
              showTimeSelect
              timeFormat="HH:mm"
              timeIntervals={15}
              dateFormat="MMMM d, yyyy h:mm aa"
              timeCaption="time"
              placeholderText="Choose date..."
            /&gt;
        &lt;/div&gt;
      );
    }
  }
  </code></pre>