Opened 6 years ago

Last modified 3 years ago

#8593 open bug

Datepicker cannot be re-opened by clicking on the text field after using the scrollbar

Reported by: glthomas224 Owned by:
Priority: minor Milestone: none
Component: ui.datepicker Version: 1.8.23
Keywords: Cc:
Blocked by: Blocking:


I am re-posting this bug because I believe that it was closed in haste by scott gonzalez. I will summarize the bug again.

The bug: If the user clicks on the scroll bar of the browser then the datepicker disappears AND the text input field that has been assigned to be a datepicker will still have focus. If the user then clicks on said input field to make the datepicker reappear after their scroll action the datepicker will NOT appear, unless the user first clicks somewhere else on the page to cause the input field to lose focus. Only after the input field loses focus can the datepicker be made to reappear by clicking again on the original input field. This is clunky performance and in my opinion this is absolutely a BUG regardless of any developers opinions on whether datepicker visibility should persist throughout mouse pointer interactions with the scrollbar of a browser. If you consider how a native non jquery/javascript dropdown combobox works, if the user clicks on the combobox it opens up the container of selction options. If the user then performs a scroll action the container of selection options disappears, but then the user can immediately reopen the combobox through the very next click on the combobox rather than having to perform an unfocus event. For this reason I have recreated this ticket.

Now my opinion also is different on what the intended behavior of a datepicker control should be in regards to persistence of the datepicker upon a scroll event. I have themed my calendar to be larger than the default calendar. Consequently sometimes my users might want to scroll the calendar depending on the current size of their browser window. My opinion is that the jquery ui datepicker should perform just like the jquery ui autocomplete combobox. If the user opens the selection container on the combobox and then performs a scroll event, then the combobox selection options remain visible. I tried investigating the javascript file for the autocomplete combobox to glean ideas about how to keep the datepicker visible when the scroll bar is selected. Unfortunately, I was unable to discover the magic code that is enabling this capability within the combobox. Until a more suitable solution can be concocted users can employ my following strategy.

On line 837 of the jquery.ui.datepicker.js file there resides a function called _checkExternalClick. The last line of this function is:


This line needs to be wrapped in the following conditional statement:

if (!$'html')) {

Once this is done, clicking on the browser scrollbar while the datepicker is visible will not hide the datepicker. However any space on the page between the body edge and the window edge is indistinguishable from the scrollbar since that space is considered to be an object of HTMLhtmlElement. The scroll bar is also considered to be an object of HTMLhtmlElement. So by creating a div container that fills this extra space between the body edge and the window edge, then the only thing left that the user can click that is considered to be an object of HTMLhtmlElement is the scrollbar. So here is the extra code needed to do this.

After the <body> tag on your page add:

<div id="UnderMask" style="position:absolute; width:0px; height:0px;
    z-index:-10000; top:0; overflow:hidden; background-color:transparent;"></div>

In your style sheet or within your <style> tags add this:


Finally just prior to the close </body> tag add the following script:

<script type="text/javascript">
jq171('#UnderMask').css('height', jq171(document).height() + 'px');
jq171('#UnderMask').css('width', jq171(window).width() + 'px');
jq171('#UnderMask').css('left', "0");
jq171(window).resize(function () {
    if (jq171(window).width() < jq171('body').width()) {
        jq171('html').css('overflow-x', 'scroll');
    else {
        jq171('html').css('overflow-x', 'hidden');
    jq171('#UnderMask').css('width', jq171(window).width() + 'px');

This isnt't the most elegant of solutions but it should suffice until the the jquery ui gods can concoct a more standalone solution which doesnt require the user to add extraneous objects. Another approach might be to measure where the coordinates of the click occurred and compare that with the coordinates of the browser's scrollbar.

Please don't close this ticket until at a minimum the bug I've described is resolved, regardless of one's datepicker persistence opinions!

Change History (10)

comment:1 Changed 6 years ago by Scott González


comment:2 Changed 6 years ago by mikesherov

Resolution: duplicate
Status: newclosed

Duplicate of #8592.
Thanks for contributing! The maintainers of the datepicker plugin responded to your request and have said what their opinion is.

Rather than opening another ticket saying the same thing, fork the project on and maintain your own fork that has the behavior that matches *your* opinion rather than their opinion.

comment:3 Changed 6 years ago by fvox13

The issue is not "the datepicker closes on scroll". That's fine, and I would think acceptable behavior for this plugin.

The issue is "the field with the datepicker retains focus, which prevents the datepicker from reopening until you first click somewhere else on the page." This *is* a fairly serious usability bug. Not some dude's opinion.

comment:4 Changed 6 years ago by mikesherov

Resolution: duplicate
Status: closedreopened

Thanks for clarifying and following up! I couldn't repro this issue at first because I'm on a Mac and scrollbars don't exist by default. But now I see what you're saying. Confirmed.

comment:5 Changed 6 years ago by mikesherov

Status: reopenedopen

comment:6 Changed 6 years ago by rnrvenkat


I have added this below function its works well. thank you for your guidelines.

[ code deleted]

Last edited 6 years ago by Scott González (previous) (diff)

comment:7 Changed 6 years ago by Scott González

@rnrvenkat If you would like to propose a fix, please sign our CLA and send a pull request for Thanks.

comment:8 Changed 5 years ago by Scott González

Milestone: 1.11.0none

comment:9 Changed 5 years ago by Scott González

Summary: Datepicker disappears upon scrollDatepicker cannot be re-opened by clicking on the text field after using the scrollbar

comment:10 Changed 3 years ago by Aleksander Machniak

This has nothing to do with a scrollbar at all. Steps:

  1. Goto input field, calendar appears,
  2. Select a date - date will be inserted to the input, the input still has focus,
  3. Now you can't open the calendar again by just clicking the input (e.g. in case you made a mistake selecting the date).

This can be simply fixed by assigning onclick event to the input, not only onfocus.

Note: See TracTickets for help on using tickets.