The chosen behaviour doesn't take resize events into account.
Consequently, when a resize occurs, the chosen-generated markup retains a fixed, un-overrideable size in a style attribute that may not be correct for the new viewport width. The chosen library handles the same situation gracefully when used independently.
To reproduce, change the orientation of a mobile device, or use Firefox' or Chrome's Responsive Design Mode: the Chosen elements will retain their prior size after the viewport size.
A superficial reading of the code suggests to me that it should be possible to add an updateChosen() function alongside the existing createChosen() function using jQuery's .resize() method, but I haven't studied the code in detail.
| Comment | File | Size | Author |
|---|---|---|---|
| #2 | separate_pixel_and_percent_calc.patch | 1.27 KB | bedlam |
Comments
Comment #2
bedlamI dug in a bit to see what was going on, and I realize that I misconstrued the cause.
In fact what is going on with the current state of the module is that the javascript mixes percentage and pixel dimensions at line 158 and line 162 when
use_relative_widthis set:So what this means is that, when
use_relative_widthis set, the initialifcompares the pixel width ($element.width()) with a percentage.Given that 100% is usually the maximum percentage value that'll be set, and that 100px is a very small value for the size of a select, the if statement will almost always evaluate false (i.e. because the
100entered as a percentage value is smaller than the pixel value of223.9882returned by jQuery).This in turn means that we can wind up setting unhelpful values like
width: 223.9882%.The attached patch keeps percentage and pixel values in their own lanes :)
Comment #3
bedlamBy the way, this may address some of the other issues here such as https://www.drupal.org/project/chosen/issues/2828214 (there are multiple similar-sounding issues filed against the 7.x branch as well).
Comment #4
nagy.balint commentedComment #5
mr.york commentedGood patch, solved this problem.
Comment #7
nagy.balint commentedThanks!
Comment #8
bedlam