I have seen a strange behavior of jQuery UI Dialog and I am not able to understand:
- What the issue is? or
- What am I doing wrong here? or
- Is this a known bug?
Steps followed to replicate the issue:
- Open the jQuery UI dialog by clicking on the New / More buttons.
- Then try re-sizing the dialog vertically.
- You will see the abnormality that width of the dialog’s content decreases automatically, making a scrollbar to appear inside the dialog.
EDIT: I see that if I remove twitter bootstrap from the page then the issue still appears but is not much noticeable. whatever be the reason I cannot remove twitter bootstrap from my page because it is being used in all other places in my current project.
Before re-sizing
After re-sizing
Here is my jQuery code. Please check the JSFiddle here:
$(document).on("click", "#btnNew", function () {
$("#popOutNewFolder").dialog({
show: "blind",
hide: "blind",
modal: true
});
});
$(document).on("click", "#btnMore", function () {
$("#popOutMoreFolder").dialog({
show: "blind",
hide: "blind",
modal: true
});
});
6
Answers
I did some more research and found out that this is a known bug (jQuery UI Team knows about the bug). And they have several Tickets assigned to this bug. If you want to follow their bug tracking then look here:
I found a workaround until they (jQuery UI Team) find a solution to the bug. Workaround is to make use of
resizeStop
event of the Dialog while initializing the dialog. So the code would look like this:EDIT (28th Aug 2018): I found @Dev-iGi's solution to be better. So marking it as an answer. I updated my solution to include his. Check here: JSFiddle link
That css worked for me:
Based off of Khurram’s solution, this is more robust, as it doesn’t use magic numbers, but instead accounts for the paddings.
I also chose to do it on the
resize
event instead ofresizeStop
, as then it doesn’t jump back and forth. Updated JSFiddleI use the following which is a result from the temporary solution from #10069 and it shows reducing or removing the default big padding can cause this issue.
I didn’t want to use a hardcoded number of pixels (like
- 34
in another answer) because that’s just never a good idea. At some point, it’ll be a different size (maybe using a different theme) and the fix will not work anymore.The answer with the CSS fix didn’t work right in my case but gave me the right hint.
So here’s another “fix”/workaround that’s simple:
Or inline:
Tested with jQuery UI v1.11.
It’s just plain awkward that this very basic feature has been broken for so long. Unfortunately, most of the jQuery bug reports don’t offer an acceptable solution.
In the tickets #8506 and #9832, it is mentioned, that the bug has to do with different
box-sizing
set. Obviously the calculation of the dialog/content doesn’t work right if the dialog container or the dialog content are notbox-sizing: content-box
.Best solution for me was adding this to the css:
Updated jsFiddle with this fix.