Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React datepicker cutting calendar on mobile screen

I am using react-datepicker.

I have two datepicker in the one line, and it is working perfect on desktop screen but when using it on mobile screen, calendar is cutting from right side as it did not got enough space from right side.

Further, It is also not showing scrollbar to scroll to right side.

Below is the image how it looks on mobile.

image_on_mobile

like image 474
Rajat Avatar asked Jan 02 '19 08:01

Rajat


3 Answers

I just came across this issue

On smaller viewports, the calendar is cutoff by the window. (overflows off screen to right or the left)

In order to solve this issue, I had to use the popperModifiers prop

More specifically, popperModifiers.preventOverflow

<DatePicker
  ...
  popperModifiers={{
    preventOverflow: {
      enabled: true,
    },
  }}
</DatePicker>

Checkout the popperModifiers Docs Here

like image 100
schmerb Avatar answered Oct 07 '22 09:10

schmerb


After doing a little research into the repository, it appears this is a known issue. One suggestion is to use the portal version of the date picker, which puts the date picker in a modal. You could preserve the current behavior for larger screens and use the portal solution for mobile only.

enter image description here

like image 28
Andy Hoffman Avatar answered Oct 07 '22 09:10

Andy Hoffman


I fixed this by using the following code:

.react-datepicker{
    position:absolute !important;
    right: -290px !important;
}

This fixes the problem for all screen sizes

You won't see the .react-datepicker class in your css. This is built into the npm package.

You will have to play with the right: -290px figure to get the right figure that works for your code.

enter image description here

like image 30
Colfah Avatar answered Oct 07 '22 10:10

Colfah