簡體   English   中英

react-dates DayPickerRangeController,如果用戶在已選擇時單擊它,是否有辦法清除 startDate 或 endDate?

[英]react-dates DayPickerRangeController, is there a way to clean startDate or endDate if user clicks it when already selected?

我試圖找到一種方法,讓用戶單擊已選擇的日期時取消選擇當前選定的日期。 我正在使用react-dates庫中的DayPickerRangeController

這是我的源代碼:

   constructor(props) {
        super(props);

        this.state = {
            startDate: null,
            endDate: null,
            focusedInput: 'startDate'
        }
    }

    handleDateChange = ({ startDate, endDate }) => {
        this.setState({ startDate, endDate });
    }

    handleFocusChange = focusedInput => {
        this.setState({ focusedInput: focusedInput || 'startDate' })
    }

    dayClick = date => {
        console.log(date)
    }


    render() {

        return (
                <DayPickerRangeController
                    onDatesChange={this.handleDateChange}
                    focusedInput={this.state.focusedInput}
                    onFocusChange={this.handleFocusChange}
                    startDate={this.state.startDate}
                    endDate={this.state.endDate}
                />
        )
    } 

如果我清楚地理解您的問題,您必須設置minimumNights={1}屬性以不允許用戶選擇所選日期。

<DayPickerRangeController
  onDatesChange={this.handleDateChange}
  focusedInput={this.state.focusedInput}
  onFocusChange={this.handleFocusChange}
  startDate={this.state.startDate}
  endDate={this.state.endDate}
  minimumNights={1}
 /> 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM