问题
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