wakirin / Litepicker

Date range picker - lightweight, no dependencies
MIT License
896 stars 132 forks source link

Picker appears offscreen when using parentEl that has relative positioning #261

Open ClayMDMI opened 3 years ago

ClayMDMI commented 3 years ago

Report When creating a picker and passing a parent element that is relatively positioned as an option, the picker does not match the input and can potentially be shown off screen.

var parent = $(this).parent()[0];
var picker = new Litepicker({
    element: this,
    parentEl: parent,
    singleMode: false,
    format: "MM/DD/YYYY",
    autoApply: true
});

image

Manually removing the top and left css properties moves the picker to the correct location, directly under the input element.

To Reproduce Steps to reproduce the behavior:

  1. Create a new div that is relatively positioned and has the following CSS: position: relative; left: 150px;
  2. Place and initialize a Litepicker input inside the div, setting the parentEl option to the div above.
  3. Click the input
  4. The picker appears to the right of the input, a total of 300px

Expected behavior I would expect that no matter the position of the parent element, the picker would detect that location and appear underneath it.

jsfiddle.net https://jsfiddle.net/ux12yg6L/

bowiechang commented 2 years ago

I faced this too, thanks for sharing. Overriding the css seems to be a great way.

bjornandrip commented 1 year ago

I to am facing a similar issue. I have litepicker with a custom parentEl that is positioned far down on a page. So when the litepicker is shown it calculates it position relative to the pody instead of the set parentEl which makes it appear somewhere way further down than it should.

Did you have any luck?