Only trim input_width to container_width when calculable. #2880
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 to fix #2480.
This PR adjusts the logic used to calculate the width of the text input when in multi-select mode.
If Chosen is not visible when initialized (it’s within a hidden container), the calculated width of Chosen’s container is
0
. This means that we’re setting the search input width to an initial value of-10px
, which is nonsense — resulting in a fallback to it’s default width in CSS (25px).This, of course, is adjusted after Chosen is interacted with, since it is now visible and the container width can be correctly calculated.
Since we don’t know when Chosen becomes visible, I propose we adjust the default width for the search input to be the full calculated width, and ignore the calculated container_width if it results in zero. The text doesn’t actually overflow outside of the container — the only downside is that a few pixels of space isn’t present.
Here’s a GIF of Chosen (which was rendered off-screen initially) being opened and closed. Before, the width of the search input was not contained to the container, and after it is:
If you didn’t catch it, look for the tail end of the “a” character. This is significantly better than what’s currently happening — the input is rendered at 25px wide: