Change the Way Width is Determined #1439
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
@harvesthq/chosen-developers
This fixes some issues that come when applying Chosen to a
select
that is not visible (when you haven't setwidth: n
for whatever reason). Basically, it uses jQuery & Prototypes magic methods for getting width if they're set and falls back tooffsetWidth
if they're not. As always, a width specified in the option object will take precedence.I went a little crazy testing this. Each of these fiddles demonstrates 4 ways you would apply width to Chosen in both a container that is hidden on page load and a container that is visible on page load. As you can see, with the exception of a hidden select that has no style applied to it, the new version does a wonderful job of matching size:
Please Note: This doesn't fix the % width issue (people will still need to specify those via
width: %
. I only mention this because one of these examples uses a percentage width set via a class. If you adjust the width of the output area, Chosen might not match it's original field. The best thing to do is adjust the width of the area and then click "Run" again. (Can you tell I learned this the hard way?)