Skip to content

Commit

Permalink
Move chosen-single’s search input to avoid clip.
Browse files Browse the repository at this point in the history
We need not rely on clip: rect() if we move the input — we can instead use display: block/none.
  • Loading branch information
adunkman committed Jan 19, 2018
1 parent d9a91ae commit 290ba2c
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 3 deletions.
7 changes: 7 additions & 0 deletions coffee/chosen.jquery.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,9 @@ class Chosen extends AbstractChosen
@form_field_jq.trigger("chosen:maxselected", {chosen: this})
return false

unless @is_multiple
@search_container.append @search_field

@container.addClass "chosen-with-drop"
@results_showing = true

Expand All @@ -259,6 +262,10 @@ class Chosen extends AbstractChosen
if @results_showing
this.result_clear_highlight()

unless @is_multiple
@selected_item.prepend @search_field
@search_field.focus()

@container.removeClass "chosen-with-drop"
@form_field_jq.trigger("chosen:hiding_dropdown", {chosen: this})

Expand Down
7 changes: 7 additions & 0 deletions coffee/chosen.proto.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,9 @@ class @Chosen extends AbstractChosen
@form_field.fire("chosen:maxselected", {chosen: this})
return false

unless @is_multiple
@search_container.insert @search_field

@container.addClassName "chosen-with-drop"
@results_showing = true

Expand All @@ -251,6 +254,10 @@ class @Chosen extends AbstractChosen
if @results_showing
this.result_clear_highlight()

unless @is_multiple
@selected_item.insert top: @search_field
@search_field.focus()

@container.removeClassName "chosen-with-drop"
@form_field.fire("chosen:hiding_dropdown", {chosen: this})

Expand Down
2 changes: 1 addition & 1 deletion coffee/lib/abstract-chosen.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -332,12 +332,12 @@ class AbstractChosen
get_single_html: ->
"""
<a class="chosen-single chosen-default">
<input class="chosen-search-input" type="text" autocomplete="off" />
<span>#{@default_text}</span>
<div><b></b></div>
</a>
<div class="chosen-drop">
<div class="chosen-search">
<input class="chosen-search-input" type="text" autocomplete="off" />
</div>
<ul class="chosen-results"></ul>
</div>
Expand Down
10 changes: 8 additions & 2 deletions sass/chosen.scss
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ $chosen-sprite-retina: url('[email protected]') !default;
border-top: 0;
background: #fff;
box-shadow: 0 4px 5px rgba(#000,.15);
clip: rect(0,0,0,0);
display: none;
}
&.chosen-with-drop .chosen-drop {
clip: auto;
display: block;
}
a{
cursor: pointer;
Expand Down Expand Up @@ -65,6 +65,12 @@ $chosen-sprite-retina: url('[email protected]') !default;
text-decoration: none;
white-space: nowrap;
line-height: 24px;

input[type="text"] {
cursor: pointer;
opacity: 0;
position: absolute;
}
}
.chosen-default {
color: #999;
Expand Down

0 comments on commit 290ba2c

Please sign in to comment.