react-dates responsive daterangepicker

给你一囗甜甜゛ 提交于 2020-08-05 09:35:55

问题


I am using a react-dates plugin from Airbnb in one of my projects. I am using daterangepicker default calendar props like this one http://airbnb.io/react-dates/?path=/story/drp-calendar-props--default. But this is not responsive in smaller devices from tab to mobile. I want to make some changes here in the tab and mobile view like it would appear as a vertical calendar as this http://airbnb.io/react-dates/?path=/story/drp-calendar-props--vertical. I want to achieve this using the given props in the docs and make changes in CSS using media queries. This is my implementation so far:

<DateRangePicker
      startDate={startDate}
      startDateId="startDate"
      endDate={endDate}
      endDateId="startDate"
      customInputIcon={customInputIcon}
      onDatesChange={this.onDatesChange}
      focusedInput={focusedInput}
      onFocusChange={this.onFocusChange}
      hideKeyboardShortcutsPanel={hideKeyboardShortcutsPanel}
      appendToBody={true}
      navPrev={navPrev}
      navNext={navNext}
      isOutsideRange={this.isOutsideRange}
    />

which looks like this I want to achieve a view like this in tab and mobile devices

But not sure about how to do the implementation in this case of responsiveness.


回答1:


You can achieve that by adding orientation prop

To differentiate it based on responsiveness, you can do

const orientation = window.matchMedia("(max-width: 700px)").matches ? 'vertical' : 'horizontal'

<DateRangePickerWrapper orientation={orientation} autoFocus />



来源:https://stackoverflow.com/questions/63166112/react-dates-responsive-daterangepicker

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!