Skip to content

Rounding error in datepicker _checkOffset() #2017

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
janis-ps opened this issue Nov 16, 2021 · 2 comments
Open

Rounding error in datepicker _checkOffset() #2017

janis-ps opened this issue Nov 16, 2021 · 2 comments

Comments

@janis-ps
Copy link

We encountered a problem where the datepicker position would be incorrect for a date input inside a Bootstrap modal. The datepicker would end up offscreen, far below the actual input element.

The culprit was this line of code (as well as the line above it):

https://github.com/jquery/jquery-ui/blob/main/ui/widgets/datepicker.js#L931

This code uses strict equality (===) to compare two floating-point numbers; not pixels, but fractions of pixels. Here's how we fixed it (and how the line above it should be fixed):

                offset.left -= ( this._get( inst, "isRTL" ) ? ( dpWidth - inputWidth ) : 0 );
                offset.left -= ( isFixed && offset.left === inst.input.offset().left ) ? $( document ).scrollLeft() : 0;
-               offset.top -= ( isFixed && offset.top === ( inst.input.offset().top + inputHeight ) ) ? $( document ).scrollTop() : 0;
+               offset.top -= ( isFixed && Math.floor(offset.top) === Math.floor( inst.input.offset().top + inputHeight ) ) ? $( document ).scrollTop() : 0;
 
                // Now check if datepicker is showing outside window viewport - move to a better place if so.
                offset.left -= Math.min( offset.left, ( offset.left + dpWidth > viewWidth && viewWidth > dpWidth ) ?
@fgerodez
Copy link

fgerodez commented May 12, 2023

Encountered this as well in 1.13.1

Applied the patch and it solved the issue, thanks

@andrerom
Copy link

andrerom commented May 9, 2025

Can confirm this fixed offset.top bug for me on Firefox (135 & 138), when Datepicker is placed inside Bootstrap modal.
Top ended up being set to twice the size of my screen height, some 2400px, making it invisible.

For some reason not this issue in Chrome.

1.13.2 and 1.14.1 with jQuery 3.7.1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

4 participants