jquery / jquery-ui

The official jQuery user interface library.
https://jqueryui.com
Other
11.25k stars 5.33k forks source link

The zoom property of css changed by brower/W3C and JqueryUI component is affected #2292

Open wesoft2020 opened 1 week ago

wesoft2020 commented 1 week ago

Description

Steps to reproduce the problem

testJquery.zip 1.write the code like "document.body.style.zoom=1.2" in javascript. 2.create a date component of jqueryUI like $( "#datepicker" ).datepicker({}); 3.open the html and focus in the date component, the popup is Misplaced image

Cause estimation

https://drafts.csswg.org/css-viewport/#zoom-om The W3C standard for the Zoom attribute has been changed so that the getBoundingClientRect, getClientRects, and IntersectionObserver APIs return rects with scaled lengths by browser, which returned rects with unscaled lengths before. So the offset() method developed on getBoundingClientRect also changed, return rects with scaled lengths now.

Please let us know will jquery or jqueryUI Do some correspondence. We did this temporarily. var originalOffset = $.fn.offset; $.fn.offset = function() {

var originalResult = originalOffset.apply(this, arguments); originalResult.top = originalResult.top / document.body.style.zoom; originalResult.left = originalResult.left / document.body.style.zoom; return originalResult; }

mgol commented 5 days ago

I moved the issue to the jQuery UI repo as that's where jQuery UI issues should be reported.

Thanks for the report. Does the issue you describe exist when jQuery UI 1.12.1 is used or only with jQuery UI 1.13.0 or newer?

mgol commented 5 days ago

OK, I checked myself in the template, it's reproducible in jQuery UI 1.12.1 as well.

Since the issue is already in 1.12, given limited team resources it's not likely to be fixed by the UI team; see the project status at https://blog.jqueryui.com/2021/10/jquery-maintainers-update-and-transition-jquery-ui-as-part-of-overall-modernization-efforts/. PRs are welcome if they're not too complex and contain tests.

wesoft2020 commented 5 days ago

Thank you very much for your response! However, this issue isn't confined to the datetimepicker; other jQuery UI controls like autocomplete also exhibit similar problems. Additionally, other UI frameworks built on jQuery, such as jQuery Bootstrap Datetimepicker JA, face the same issue.

The root cause appears to be the use of jQuery's offset() method. The coordinates returned by this method now include zoom attributes in the latest browsers, which wasn't previously the case.

Therefore, I believe the problem doesn't lie with the UI framework itself but with the jQuery offset() method. I suggest we move away from using getBoundingClientRect() for HTML controls and instead use the offsetTop attribute. We have temporarily corrected this in our web application.

I welcome further discussion on this approach.

mgol commented 4 days ago

@wesoft2020 can you prepare an isolated test case that just uses jQuery, without jQuery UI or other libraries? Then it will be clearer what the issue with jQuery is and we’ll be able to open a new jQuery issue about it.

markvantilburg commented 2 days ago

When i zoom the browser with ctrl-scroll it works fine. But the javascript zoom does something strange.

I created this fiddle: https://jsfiddle.net/geovd7L6/

wesoft2020 commented 1 day ago

@mgol I created a page that displays the offset length using jQuery and the browser. The browser has updated its API for the W3C zoom property, while jQuery continues to use the same API as before, I think. OffsetLengthTest.zip

Install old chrome version: npx @puppeteer/browsers install chrome@127 https://developer.chrome.com/blog/chrome-for-testing?hl=ja

@markvantilburg Thanks for the discussion! This issue is only affected by the Computed Style APIs, so the browser's zoom works fine.