简体   繁体   English

是否可以持续显示 Airbnb 反应日期日历?

[英]Is it possible to persistently display Airbnb react-dates calendar?

I'm trying to have Airbnb's react-dates library display the calendar persistently (ie not have it act like a drawer/modal that toggles it's visibility).我正在尝试让 Airbnb 的react-dates库持续显示日历(即,不要让它像抽屉/模式一样切换其可见性)。

I've looked through the documentation and noticed the appendToBody prop, but that just puts the DayPickerRangeController behind the input fields.我查看了文档并注意到了appendToBody道具,但这只是将DayPickerRangeController放在输入字段后面。 It gets somewhat close, in that the calendar is somewhat CSS blocked, but it's still a drawer/modal that disappears.它有点接近,因为日历在某种程度上被 CSS 阻止,但它仍然是一个消失的抽屉/模式。

I've looked through the CSS and can get the calendar to display inline-block basically when an input field is focused by removing the position: absolute CSS value on the DateRangePicker_picker div element.我已经查看了 CSS 并且可以通过删除DateRangePicker_picker div 元素上的position: absolute CSS 值来使日历显示inline-block基本上当输入字段聚焦时。 However, it still disappears when the input focus is lost.但是,当失去输入焦点时,它仍然会消失。

The other approach I tried was to use the internal components that DateRangePicker is using (eg DateRangePickerInputController and DayPickerRangeController ).我尝试的另一种方法是使用DateRangePicker正在使用的内部组件(例如DateRangePickerInputControllerDayPickerRangeController )。 I am able to have more control from a visual layout standpoint, but I lose all built-in functionality that the DateRangePicker has in terms of selecting days/dates/ranges and sending that info back.从视觉布局的角度来看,我能够进行更多控制,但是我失去了DateRangePicker在选择天数/日期/范围并将该信息发回方面的所有内置功能。

<DateRangePickerInputController
  readOnly 
  endDate={endDate} 
  endDateId="endDate" 
  endDatePlaceholderText="mm/dd/yyyy" 
  isEndDateFocused={focusedInput === 'endDate'}
  isStartDateFocused={focusedInput === 'startDate'}
  startDate={startDate} 
  startDateId="startDate" 
  startDatePlaceholderText="mm/dd/yyyy" 
/>
<DayPickerRangeController
  noBorder
  endDate={endDate} 
  focusedInput={focusedInput} 
  initialVisibleMonth={() => !startDate ? moment().subtract(1, 'M') : startDate }
  isOutsideRange={isOutsideRange.bind(this)} 
  minimumNights={0} 
  numberOfMonths={numberOfMonths}
  onDatesChange={onDatesChange.bind(this)} 
  onFocusChange={onFocusChange.bind(this)} 
  orientation={orientation}
  startDate={startDate} 
/>

As I mentioned, the elements render the way I want them to in that the calendar and inputs are persistent and stacked "on top" of each other.正如我所提到的,这些元素按照我希望的方式呈现,因为日历和输入是持久的,并且彼此堆叠在“顶部”。

And only 1 month shows up correctly, but when I click on a day in the calendar, the startDate input field does not update.并且只有 1 个月正确显示,但是当我单击日历中的一天时, startDate输入字段不会更新。 Same for endDate .endDate相同。 The hover highlighting over the days in the calendar is gone.在日历中突出显示日期的悬停消失了。 And individual day highlights/coloring is gone when I click on them.当我点击它们时,个别日子的亮点/着色消失了。

您可以使用props renderCalendarInfo并通过它传输DateRangePickerInputController

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

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