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

Using orientation:auto but date picker still appears above, cut off, when there plenty of space below.

Open trusktr opened this issue 11 years ago • 29 comments

In the screenshot, the orientation is set to "auto" so we'd expect the calendar to appear below insead of cut off above:

screen shot 2015-03-17 at 1 00 23 pm

trusktr avatar Mar 17 '15 20:03 trusktr

Thanks for the bug report! It's indeed an issue and we will try to fix it soon. This is an example to show to issue

acrobat avatar Mar 17 '15 20:03 acrobat

capture

I did a workaround by changing the following line:

    if (Math.max(top_overflow, bottom_overflow) === bottom_overflow)
        yorient = 'top';

To:

    if (Math.max(top_overflow, bottom_overflow) === bottom_overflow || scrollTop === 0)
        yorient = 'top';

This is the result: capture

osama9 avatar Mar 23 '15 08:03 osama9

Thanks @osama9! The fix you propose is possibly also a fix for #1286, I will take a look at it later today!

acrobat avatar Mar 23 '15 08:03 acrobat

Hmm there's definitely something else causing this then, as that fix hasn't solved my issue (though circumstances are probably different).

Mine still goes out of view when the orientation is set to "auto":

So something in the auto logic is missing when the picker is at the very top of a fixed-position element (a panel stuck to the side in my app). Any ideas?

torrobinson avatar Apr 12 '15 01:04 torrobinson

:+1:

The proposed javascript workaround works fine for datepickers which open to the top (and fall off the screen) but not for ones opening to the bottom.

lode avatar May 11 '15 12:05 lode

you can use container to solve this

    $('#date-range').datepicker({
        format: 'yyyy-mm-dd', 
        clearBtn: true,
        autoclose: true,
        disableTouchKeyboard: true,
        inputs: $('input[name="date-range-start-date"],input[name="date-range-end-date"]').toArray(),
        container: '#date-range-picker-container'
    });

alvin0618 avatar May 21 '15 06:05 alvin0618

Alternative solution:

if (Math.max(top_overflow, bottom_overflow) === bottom_overflow && top_overflow > 0 || scrollTop > 0)

asessa avatar Jun 26 '15 15:06 asessa

I've updated it again with a more simple

if (top_overflow > 0)

Always display calendar on top if there is space.

I've forked the fiddle example, can you test this ?

Example:

http://jsfiddle.net/asessa/pnd6e36k/

asessa avatar Jul 11 '15 19:07 asessa

Looks promising! In my own project (behind closed doors sorry) I only see one problem: it falls behind a fixed positioned element, instead of dropping in the other direction.

Further, also in the fiddle, the little arrow is wrongly positioned. Pointing the other direction as the input field is.

lode avatar Jul 11 '15 20:07 lode

Looks like the css (position-bottom / top) are inverted, updated.

http://jsfiddle.net/asessa/pnd6e36k/2/

asessa avatar Jul 12 '15 00:07 asessa

I found a simple repro for the problem I'm having with fixed elements: using the default fixed navbar from bootstrap: http://jsfiddle.net/4hmcd1ug/

But maybe this is another bug, making it work with fixed navbars.

lode avatar Jul 12 '15 12:07 lode

Do you mean this:

http://jsfiddle.net/asessa/4hmcd1ug/1/

asessa avatar Jul 12 '15 13:07 asessa

Test with scrolling:

http://jsfiddle.net/asessa/4hmcd1ug/2/

asessa avatar Jul 12 '15 13:07 asessa

Sorry, forgot to save: http://jsfiddle.net/4hmcd1ug/4/

Just before it should dropdown, it falls behind the navbar.

datepicker-with-fixed-navbar

lode avatar Jul 12 '15 13:07 lode

It's a z-index problem because can't retreive nav (using parents) z-index. I've set a minimum z-index of 1080, maximum z-index on bootstrap is currently 1070 used by tooltip, so this should work with any bootstrap component.

http://jsfiddle.net/asessa/4hmcd1ug/5/

asessa avatar Jul 13 '15 11:07 asessa

Yeah. Of course.

Maybe good to pick a z-index which sits at a correct hierarchy? Above elements which are always there like a navbar but below interactive elements like a tooltip? In that way a tooltip inside the datepicker would still work.

lode avatar Jul 13 '15 11:07 lode

@asessa , your fix works for me except for when I minify the javascript. If I deploy with non-minified js, it works. Not sure why that is. It was the same way with the version you didn't modify.

richinator38 avatar Jul 15 '15 16:07 richinator38

@richinator38 there were a few console.log used for debugging, try with this version please: http://jsfiddle.net/asessa/4hmcd1ug/6/

asessa avatar Jul 15 '15 16:07 asessa

Didn't work. calendar-issue

richinator38 avatar Jul 15 '15 16:07 richinator38

The blue bar is a fixed navbar ? what is the current z-index ?

asessa avatar Jul 15 '15 16:07 asessa