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

I want to change the position of the calendar

Open madoka1234567 opened this issue 8 years ago • 20 comments

The calendar is hidden on the smartphone. Can you adjust the position?

2018-01-31 10 56 41

madoka1234567 avatar Jan 31 '18 01:01 madoka1234567

Have the same issue. Want to move it left depends on input position. Someone know how to do that ?).

This params will help you: 'auto', 'auto-left', 'auto-right', 'bottom', 'bottom-end', 'bottom-start', 'left', 'left-end', 'left-start', 'right', 'right-end', 'right-start', 'top', 'top-end', 'top-start'

Found params in src. You need to pass one of this values to popperPlacement props to the DatePicker component like that - <DatePicker popperPlacement="bottom-end" />.

Someone who knows how to contact with develop team tell them to update popperPlacement docs. It's not so clear to find this values. Thx.

postal286 avatar Jan 31 '18 06:01 postal286

I'm so grateful for that!

madoka1234567 avatar Jan 31 '18 09:01 madoka1234567

Unfortunately, placement does not work for me, nor does it work in the official examples. I would expect placement to force the popper to appear on the bottom, etc.

benjaminkniaz avatar Sep 21 '18 15:09 benjaminkniaz

Yep - as @benjaminkniaz says it doesn't force the position. if I say top-start I would expect to force that position even if it's near the screen edge.

robhadfield avatar Sep 28 '18 15:09 robhadfield

@robhadfield turns out you have to add a modifier to force the position. flip forces it not to flip even if the popper is going to be partially off-screen, and preventOverflow prevents it from covering the element you clicked, if again the popper detects the item will partially go off screen.

This is where I found the modifiers: https://github.com/FezVrasta/popper.js/blob/master/docs/_includes/popper-documentation.md#modifiers..flip

<DatePicker
    selected={props.followup_complete_by_dt}
    onChange={props.handleDueDateChange}
    className="form-control"
    monthsShown={1}
    popperPlacement="bottom"
    popperModifiers={{
        flip: {
            behavior: ["bottom"] // don't allow it to flip to be above
        },
        preventOverflow: {
            enabled: false // tell it not to try to stay within the view (this prevents the popper from covering the element you clicked)
        },
        hide: {
            enabled: false // turn off since needs preventOverflow to be enabled
        }
    }}
/>

benjaminkniaz avatar Oct 01 '18 18:10 benjaminkniaz

Thanks a lot @benjaminkniaz , I'll give that a go. I ended up reverting to a dialog which really ruins the flow.

EDIT: @benjaminkniaz - worked perfectly, thanks!

robhadfield avatar Oct 01 '18 18:10 robhadfield

I'm still running into an issue where the popup appears off to the left. Any idea why it might be doing? image image

ryanlozon avatar Oct 16 '18 09:10 ryanlozon

Here's the settings that work for me:

            <Picker
                showMonthDropdown
                showYearDropdown
                dropdownMode="select"
                dateFormat={ dateFormat }
                minDate={ isDate(minDate) ? moment(minDate) : null }
                maxDate={ isDate(maxDate) ? moment(maxDate) : null }
                placeholderText={ placeholder }
                selected={ date && isDate(date) ? moment(date) : initialDate }
                onChange={ onChange }
                disabled={ disabled }
                withPortal={ withPortal ? true : false }
                popperPlacement='bottom'
                popperModifiers={{
                    flip: {
                        behavior: ['bottom'] // don't allow it to flip to be above
                    },
                    preventOverflow: {
                        enabled: false // tell it not to try to stay within the view (this prevents the popper from covering the element you clicked)
                    },
                    hide: {
                        enabled: false // turn off since needs preventOverflow to be enabled
                    }
                }}
            />

robhadfield avatar Oct 16 '18 11:10 robhadfield

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Aug 30 '19 13:08 stale[bot]

Screenshot 2020-04-23 at 17 09 07 Hi any possible solution to this issue? the datepicker is overlapped with the dates on calendar

jacky-ew avatar Apr 23 '20 09:04 jacky-ew

@jacky-ew Looks like a z-index issue between the picker and Calendar, try dropping your calendar down to z-index:1 ?

robhadfield avatar Apr 23 '20 09:04 robhadfield

Hi i think its better to set datepicker popper to have z-index: 1, but cannot find props in the lib

jacky-ew avatar Apr 24 '20 02:04 jacky-ew

managed to solved it by adding z-index in div container instead, thank you @robhadfield

jacky-ew avatar Apr 24 '20 03:04 jacky-ew

Difficult to advise without seeing the live code but glad you got it working 👍

robhadfield avatar Apr 24 '20 14:04 robhadfield

Have the same issue. Want to move it left depends on input position. Someone know how to do that ?).

This params will help you: 'auto', 'auto-left', 'auto-right', 'bottom', 'bottom-end', 'bottom-start', 'left', 'left-end', 'left-start', 'right', 'right-end', 'right-start', 'top', 'top-end', 'top-start'

Found params in src. You need to pass one of this values to popperPlacement props to the DatePicker component like that - <DatePicker popperPlacement="bottom-end" />.

Someone who knows how to contact with develop team tell them to update popperPlacement docs. It's not so clear to find this values. Thx. Awesome Man!!!

raki-rankawat avatar Jul 20 '20 09:07 raki-rankawat

Have the same issue. Want to move it left depends on input position. Someone know how to do that ?).

This params will help you: 'auto', 'auto-left', 'auto-right', 'bottom', 'bottom-end', 'bottom-start', 'left', 'left-end', 'left-start', 'right', 'right-end', 'right-start', 'top', 'top-end', 'top-start'

Found params in src. You need to pass one of this values to popperPlacement props to the DatePicker component like that - <DatePicker popperPlacement="bottom-end" />.

Someone who knows how to contact with develop team tell them to update popperPlacement docs. It's not so clear to find this values. Thx.

Wanted to add a little more detail to this. The react-datepicker library uses react-popper found here: https://github.com/Hacker0x01/react-datepicker/blob/1605d79c175d5448d2e1ce63e71fc1202bc50a04/src/popper_component.jsx#L4

react-popper is the wrapper for the popper library and the docs for the options are found here: https://popper.js.org/docs/v2/constructors/#options.

savtwo avatar Feb 21 '21 19:02 savtwo

Added examples to show datepicker at down side

https://infinitbility.com/how-to-show-bottom-in-react-datepicker

infinitbility avatar Jun 08 '21 15:06 infinitbility

it works form me. The DatePicker's calendar is shown on top and is prevented to be shown bottom. I used the following code added to the : <DatePicker selected={ this.state.startDate } onChange={ this.handleChange } showTimeSelect timeFormat="HH:mm" timeIntervals={5} timeCaption="time" dateFormat="MMMM d,yyyy h:mm aa" wrapperClassName="date-picker" popperPlacement="top" popperModifiers={{ flip: { behavior: ["bottom"] // don't allow it to flip to be above }, preventOverflow: { enabled: false // tell it not to try to stay within the view (this prevents the popper from covering the element you clicked) }, hide: { enabled: false // turn off since needs preventOverflow to be enabled } }} />

yannickNzali avatar Aug 10 '22 09:08 yannickNzali

@robhadfield turns out you have to add a modifier to force the position. flip forces it not to flip even if the popper is going to be partially off-screen, and preventOverflow prevents it from covering the element you clicked, if again the popper detects the item will partially go off screen.

This is where I found the modifiers: https://github.com/FezVrasta/popper.js/blob/master/docs/_includes/popper-documentation.md#modifiers..flip

<DatePicker
    selected={props.followup_complete_by_dt}
    onChange={props.handleDueDateChange}
    className="form-control"
    monthsShown={1}
    popperPlacement="bottom"
    popperModifiers={{
        flip: {
            behavior: ["bottom"] // don't allow it to flip to be above
        },
        preventOverflow: {
            enabled: false // tell it not to try to stay within the view (this prevents the popper from covering the element you clicked)
        },
        hide: {
            enabled: false // turn off since needs preventOverflow to be enabled
        }
    }}
/>

I am also running into an issue with changing the position of the datepicker, however, I tried this method as well and nothing changed. is there another dependency that needs to be installed into my application in order for the popper props to work?

krystallopez avatar Nov 16 '23 20:11 krystallopez

Any update on this issue? to force and show Date picker on bottom

Linuhusainnk avatar Jul 25 '25 10:07 Linuhusainnk