React-dates: Programatically closing calendar

Created on 4 Jul 2017  路  4Comments  路  Source: airbnb/react-dates

I've used the renderCalendarInfo function to add some pre-defined date ranges which works great.

ss

However I would like to close the calendar after clicking one of the buttons, am I able to do this?

Most helpful comment

When clicking on one of the buttons I assume that you are setting startDate and endDate, so you can maybe pass a function to the prop onDateChange and in that function you set the focusedInput to false?

All 4 comments

When clicking on one of the buttons I assume that you are setting startDate and endDate, so you can maybe pass a function to the prop onDateChange and in that function you set the focusedInput to false?

Ah yes changing focusedInput to false makes sense, thank you. I'll try that later today

hey @alexcroox can you provide the methods you used for the clickHandler on each button on the footer? I'm looking at the API but I didn't see the renderCalendarInfo https://www.diycode.cc/projects/airbnb/react-dates

@MaxiSantos
Simple example:

@autobind
onClickTodayButton() {
    this.onDateChange(moment());
    this.onFocusChange({focused: false});
}

@autobind
renderCalendarFooter() {
    return (
        <div className="date-picker-footer">
            <button className="today-button" type="button" onClick={this.onClickTodayButton}>TODAY</button>
        </div>
    );
}

render() {
    return (
        <div className="date-picker-wrapper">
            <SingleDatePicker
                ...
                renderCalendarInfo={this.renderCalendarFooter}
            />
        </div>
    );
}

Preview:
screen shot 2018-10-29 at 11 37 16

Was this page helpful?
0 / 5 - 0 ratings

Related issues

cemremengu picture cemremengu  路  3Comments

Jesus-Gonzalez picture Jesus-Gonzalez  路  3Comments

arthurvi picture arthurvi  路  3Comments

yokomizor picture yokomizor  路  3Comments

ekohanyi picture ekohanyi  路  3Comments