Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Only trim input_width to container_width when calculable. #2880

Merged
merged 1 commit into from
Sep 5, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions coffee/chosen.jquery.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -500,9 +500,8 @@ class Chosen extends AbstractChosen
width = div.width() + 25
div.remove()

container_width = @container.outerWidth()

width = Math.min(container_width - 10, width)
if @container.is(':visible')
width = Math.min(@container.outerWidth() - 10, width)
Copy link
Contributor

@satchmorun satchmorun Sep 1, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@adunkman and I paired on this, because I couldn't reproduce the issue in my jquery HTML test page.

While working on it, we discovered a fun issue with jquery's outerWidth method. The short of it is that if the element is hidden, one should not trust jquery to do anything sensible. For example, with a style of width: 98% (on a non-visible element), it will return 98. Le sigh.

So we needed to do a different thing in the jQuery version than in the prototype version.

Go early 2000s!


@search_field.width(width)

Expand Down
5 changes: 2 additions & 3 deletions coffee/chosen.proto.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -505,9 +505,8 @@ class @Chosen extends AbstractChosen
width = div.measure('width') + 25
div.remove()

container_width = @container.getWidth()

width = Math.min(container_width - 10, width)
if container_width = @container.getWidth()
width = Math.min(container_width - 10, width)

@search_field.setStyle(width: width + 'px')

Expand Down