Subpixel rounding issue causes dialog to resize unnecessarily

Created on 1 July 2024, 2 months ago
Updated 20 August 2024, 18 days ago

Problem/Motivation

When the height of the dialog title bar is a subpixel value and the height of the dialog is set to a percentage, the resetSize function in dialog.position.js will flip between setting the height to a fixed value and "auto" every time it is called because adjustedValue is rounded by running it through parseInt, whereas the actual height it is being compared to is not rounded and taken straight from event.data.$element.parent().outerHeight().
For instance: if the window height is 946px and the height is set to 75%, adjustedValue will be 709px, but event.data.$element.parent().outerHeight() will be 708.984px, which will cause the evaluation to determine it is smaller than adjustedValue, resulting in the height being set to "auto", and then back to a fixed value which repeats the cycle.
I haven't tested this on 11.x yet, but since the code is the same there, I imagine it might also cause issues under certain circumstances.
I noticed there are efforts to ditch jQuery UI dialog altogether, but I wanted to create this issue regardless, so people running into the same issue have some way to resolve it without being forced to wait for the new dialog implementation to drop.

Steps to reproduce

- Use an admin theme where the dialog title bar has a height with a subpixel value (like Gin, or zoom out 1 step with Claro).
- Open a dialog window whose size is set to a percentage value (in core it's the media library modal).
- Tigger the window resize handler multiple times and notice how the height value on #drupal-modal toggles between "auto" and a numerical pixel value.
(Tested on Chrome)

Proposed resolution

Round the height of the dialog before comparing it to the already rounded adjustedValue.

Remaining tasks

Create MR adding Math.round around event.data.$element.parent().outerHeight().
Review.

User interface changes

n/a

API changes

n/a

Data model changes

n/a

Release notes snippet

πŸ› Bug report
Status

Fixed

Version

10.4 ✨

Component
JavascriptΒ  β†’

Last updated 1 day ago

Created by

πŸ‡§πŸ‡ͺBelgium seutje Antwerp

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024