Reputation: 282885
<select>
<option class="a">aaaaa</option>
<option class="a">a</option>
<option class="a">a</option>
<option class="a">a</option>
<option class="a">a</option>
<option class="a">a</option>
<option class="a">a</option>
<option class="a">a</option>
<option class="a">a</option>
<option class="a">a</option>
<option class="a">a</option>
<option class="a">a</option>
<option class="a">a</option>
<option class="b">b</option>
<option class="b">b</option>
<option class="b">b</option>
<option class="b">b</option>
<option class="b">b</option>
<option class="b">b</option>
<option class="b">b</option>
<option class="b">b</option>
<option class="b">b</option>
<option class="b">b</option>
<option class="b">b</option>
<option class="b">b</option>
<option class="b">b</option>
<option class="b">b</option>
<option class="b">b</option>
<option class="b">b</option>
<option class="b">b</option>
<option class="b">b</option>
<option class="b">b</option>
<option class="b">b</option>
<option class="b">b</option>
<option class="b">b</option>
<option class="b">b</option>
</select>
<button>click me</button>
$('button').on('click', function(ev) {
ev.preventDefault();
$('.a').prop('disabled',true);
if($('select').find('option:selected').prop('disabled')) {
$('select').find('option:enabled:first').prop('selected',true);
};
});
option[disabled] {
display: none;
}
Open the fiddle in Chrome. Click the <select>
. Observe its height. Click the button. Open the <select>
again. Notice how much shorter it is, despite there still being plenty of values in there.
Why is Chrome excessively shortening the dropdown list? I want it to be whatever its natural height is, which should be about the same as what it was the first time you opened it. Can I force Chrome to recompute its natural height?
This example should be more clear. Pop open each of the selects. Notice they're different heights, despite displaying the same values.
Upvotes: 3
Views: 406
Reputation: 282885
It's a bug (thanks Nico for finding this) and there's no workaround (thanks Banana).
If you want the height to be computed correctly, you have to actually remove the <options>
from the DOM.
Upvotes: 3