I am using react-dates provided from Airbnb. It works perfectly for desktop and mobile view.
The only thing is when I render the calendar on mobile view. Is there any way I can create a close button for the calendar?
This is how it looks on my mobile view:
What i want is a close [X] button on the upper right corner to close the calender. Now i need to choose dates before its closed.
My code for DatePickerRange
:
import React, { useState } from 'react';
import 'react-dates/initialize';
import 'react-dates/lib/css/_datepicker.css';
import { DateRangePicker } from 'react-dates';
export default function DatePicker() {
const [startDate, setStartDate] = useState(null);
const [endDate, setEndDate] = useState(null);
const [focusedInput, setFocusedInput] = useState(null);
const setStartAndEndDate = (startDateInput, endDateInput) => {
setStartDate(startDateInput);
setEndDate(endDateInput);
};
const smallDevice = window.matchMedia('(max-width: 400px)').matches;
const orientation = smallDevice ? 'vertical' : 'horizontal';
return (
<>
<DateRangePicker
displayFormat="DD/MM/YYYY"
startDate={startDate} // momentPropTypes.momentObj or null,
startDateId="startDate" // PropTypes.string.isRequired,
endDate={endDate} // momentPropTypes.momentObj or null,
endDateId="endDate" // PropTypes.string.isRequired,
onDatesChange={({ startDate, endDate }) => setStartAndEndDate(startDate, endDate)} // PropTypes.func.isRequired,
focusedInput={focusedInput} // PropTypes.oneOf([START_DATE, END_DATE]) or null,
onFocusChange={focusedInput => setFocusedInput(focusedInput)} // PropTypes.func.isRequired,
orientation={orientation}
withPortal={smallDevice}
showClearDates
showDefaultInputIcon
hideKeyboardShortcutsPanel
/>
</>
);
}