简体   繁体   English

为 airbnb SingleDatePicker 制作下拉选择器日期

[英]making a dropdown selector date for airbnb SingleDatePicker

I've got my setup like this, I'm absolutely squeezing the limits of what is possible from outside a library:我的设置是这样的,我绝对是在挤压图书馆外部可能的极限:

const [customDate, setCustomDate] = useState(moment());
const [focused, setFocused] = useState(false);)
const onDropDownChangeMonth = ()=>{
    setCustomDate(moment('07-12-2020', dateFormat.MM_DD_YYYY));
    setFocused(true);
}

    <SingleDatePicker
              date={customDate}
              onDateChange={onDateChange}
              focused={focused}
              placeholder={props.placeholder}
              onFocusChange={(e) => {
                setFocused(e.focused); 
              }}
              navPrev={<div></div>}
              navNext={<div></div>}
              keepFocusOnInput={true}
              renderMonthText={() => (
                <div style={{ display: 'flex', flexDirection: 'row' }}>
                  <select style={{ border: 'none', background: '#ffffff' }} onChange={onDropDownChangeMonth}>
                    <option>January</option>
                    <option>February</option>
                    <option>March</option>
                    <option>April</option>
                    <option>May</option>
                    <option>June</option>
                    <option>July</option>
                    <option>August</option>
                    <option>September</option>
                    <option>October</option>
                    <option>November</option>
                    <option>December</option>
                  </select>
                </div>
              )}
            />  

so, my current implementation gives me correct result like this:所以,我目前的实现给了我这样的正确结果:

在此处输入图片说明

Since, this would re-render, I wanted to keep it open(I can bear the flicker), the date changes, the calendar changes,the calendar stays open, but, the children they render blank:因为,这会重新渲染,我想保持打开状态(我可以忍受闪烁),日期更改,日历更改,日历保持打开状态,但是,他们呈现空白的孩子:
在此处输入图片说明

Only when I manually defocus, and reopen then the calendar gets rendered, and I see the changes reflected.只有当我手动散焦并重新打开时,日历才会呈现,并且我会看到反映的更改。 How do I get the calendar rendered?如何让日历呈现? How to make it so that I don't have to manually defocus it, I don't mind the flicker.如何使它不必手动散焦,我不介意闪烁。

BTW: I'm using the SingleDatePicker by airbnb顺便说一句:我正在使用SingleDatePicker的 SingleDatePicker

Well, this is a possible solution for anyone who doesn't mind a blink instead of a flicker (please read the question above).好吧,对于那些不介意眨眼而不是闪烁的人来说,这是一个可能的解决方案(请阅读上面的问题)。 It's a hacky solution, and it doesn't do much good in my case, just noting here for someone who might be okay with this, or someone who knows how to reduce this blink to a flicker or nothing :这是一个笨拙的解决方案,在我的情况下它没有多大用处,只是在这里注意可能对此没有意见的人,或者知道如何将这种闪烁减少到闪烁或什么都不做的人

put this in the `onDropDownChangeMonth`:   
  
const onDropDownChangeMonth = ()=>{
    setCustomDate(moment('07-12-2020', dateFormat.MM_DD_YYYY));
    setFocused(false);
    setTimeout(()=>setFocused(true), 1);
}  

Even though I put a 1ms timeout, the delay for the re-render is about 1 second, and this is not good in my case.即使我设置了 1 毫秒的超时时间,重新渲染的延迟也大约是 1 秒,这对我来说并不好。 . . Please mention anything to reduce or get rid of that delay-for-re-render .请提及任何减少或摆脱延迟重新渲染的内容

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM