react-datepicker icon indicating copy to clipboard operation
react-datepicker copied to clipboard

MiddleWare offset not working

Open AlexandrTokarev opened this issue 11 months ago • 4 comments

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 avatar Mar 06 '24 08:03 AlexandrTokarev

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.

AlexandrTokarev avatar Mar 06 '24 12:03 AlexandrTokarev

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

hugoburguete avatar Apr 30 '24 17:04 hugoburguete

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.

arajpaul avatar May 30 '24 15:05 arajpaul

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"

OvechkinDmitry avatar Jun 26 '24 06:06 OvechkinDmitry