Hacker0x01 / react-datepicker

A simple and reusable datepicker component for React
https://reactdatepicker.com/
MIT License
7.96k stars 2.23k forks source link

MiddleWare offset not working #4564

Open AlexandrTokarev opened 6 months ago

AlexandrTokarev commented 6 months ago

I'm trying to change the dropdown offset. But no matter what values I set, its position does not change:

image image

Sandbox: https://codesandbox.io/p/sandbox/quizzical-fog-datepicker-test-qsnp8z

AlexandrTokarev commented 6 months ago

There is also no way to override middleware flip... I need to specify mainAxis: false. I got around it like this:

image

But I think there needs to be a better way to do this.

hugoburguete commented 4 months ago

This worked for me:

import DatePicker from "react-datepicker";
import { offset } from "@floating-ui/react";

...

<DatePicker
  ...myProps
  popperModifiers={[
    offset(20)
  ]}
/>
image

It may be worth checking what your middlewares variable is outputting.

EDIT: Flip seems to have worked for me as well with

      popperModifiers={[
        flip({ padding: 5 }),
      ]}
image

I couldn't load your sandbox example but hope these examples are of any help

arajpaul commented 3 months ago

There is also no way to override middleware flip... I need to specify mainAxis: false. I got around it like this:

image

But I think there needs to be a better way to do this.

I have the same issue and this is the only solution that worked. Setting popperModifiers doesn't override the existing middleware the datepicker has.

OvechkinDmitry commented 2 months ago

I encountered a similar problem and found this solution working for me:

popperModifiers={[
        {
          name: 'placement',
          fn: (state) => {
            const { placement, y } = state;

            return {
              ...state,
              y: placement.startsWith('bottom') ? y - 10 : y + 10, // condition for auto placement
            };
          },
        },
      ]}

current version:

"react-datepicker": "^7.1.0"