-
Notifications
You must be signed in to change notification settings - Fork 4.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Selection text gets cut off because the select is too narrow #713
Comments
@pfiller any thoughts? |
I also am having this issue. We are thinking of applying Chosen to potentially thousands of drop-downs, and having to explicitly set the widths could break many of the layouts. Bumping this up in hopes that someone has come up with a solution to this, or at least ideas we could try out. |
I too am having this issue with 0.9.11 - the only fix I have found is setting a min-width in CSS, however that has the reverse effect of having some select drop downs too large for their container. |
Just found a bit more information - calling I then put the Chosen initialization into |
Setting a width is the simplest solution by a wide margin. Chosen tries to match the space that the select box it's replacing takes up. Trying to figure out the actual length of options would add complication that can easily be avoided simply by setting a width on the original select field (or in Chosen's options). I know it's not perfect for everyone, but it's impossible to make everything perfect for everyone. |
I don't like fiddling with 3rd party code, but like a few other people, I could not just set widths in an existing app. I ended up added 10px to the calculation of the Chosen container width and it seemed to fix this issue. |
@pfiller , setting a width is:
|
A nice solution may be to provide an option to "add" pixels to the calculated width.
|
@doublesharp , I tried your experiment (let the DOM finish load first and then manually call $("select").chosen();). It does not work, the text does get cut off. |
@adrien-be , it was a while ago but that's all that I did. Keep in mind that it might still cut off the text, I was just able to get Chosen to respect the CSS defined widths of the SELECT boxes when creating its dropdowns. |
This would be a nice option to have within the plugin. Barring that though, here's a work-around to set the width of the element automatically based on the width of the placeholder text.
The drop-down will be the same size as the select element and will wrap if text is longer. If you wanted to set a specific width, you could do something like the following inside the each. If you wanted the drop-down to always expand to the full length of its options' text, you could use something like the following. Though use that with caution, because if you have lengthy options, you could end up with drop-downs that run out of your layout. |
@pfiller - If chosen matches the width of the select element, shouldn't it account for the additional margins/padding that chosen uses? I would think that having the longest option fully visible would be preferable to exactly matching the original width (which hasn't been explicitly set in the first place). E.g., http://jsfiddle.net/ng7yx2a0/ It seems that adding a fixed number of pixels as others have suggested should solve the issue, but I guess its more complex than that if it hasn't been fixed already? |
I use your code with a small modification:
|
I have this on my HTML:
I'm using this JavaScript to bind the library to the select:
And here's the final result:
It looks fine though if I use:
I think you shouldn't need to set an explicit width. It would be nice if it worked out of the box.
The text was updated successfully, but these errors were encountered: