Skip to content

Commit 73cb9ba

Browse files
committed
Fixed #87
1 parent 3d37e23 commit 73cb9ba

File tree

5 files changed

+27
-1
lines changed

5 files changed

+27
-1
lines changed

public/jquery.selectric.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,8 +281,11 @@
281281
/** Activates the plugin */
282282
activate: function() {
283283
var _this = this;
284+
var hiddenChildren = _this.elements.items.closest(':visible').children(':hidden').addClass(_this.classes.tempshow);
284285
var originalWidth = _this.$element.width();
285286

287+
hiddenChildren.removeClass(_this.classes.tempshow);
288+
286289
_this.utils.triggerCallback('BeforeActivate', _this);
287290

288291
_this.elements.outerWrapper.prop('class',

public/jquery.selectric.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/jquery.selectric.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,8 +264,11 @@
264264
/** Activates the plugin */
265265
activate: function() {
266266
var _this = this;
267+
var hiddenChildren = _this.elements.items.closest(':visible').children(':hidden').addClass(_this.classes.tempshow);
267268
var originalWidth = _this.$element.width();
268269

270+
hiddenChildren.removeClass(_this.classes.tempshow);
271+
269272
_this.utils.triggerCallback('BeforeActivate', _this);
270273

271274
_this.elements.outerWrapper.prop('class',

test/basic.spec.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,17 @@ describe('basic suite', function() {
155155
expect($('.selectric-wrapper').width()).toBe(selectWidth);
156156
});
157157

158+
it('should have same width of original <select> even if parent is hidden', function() {
159+
loadFixtures('hidden.html');
160+
var selectHidden = $('#select-hidden').selectric({
161+
inheritOriginalWidth: true
162+
});
163+
selectHidden.closest('.wrapper').show();
164+
var selectWidth = selectHidden.width();
165+
selectHidden.closest('.wrapper').hide();
166+
expect($('.selectric-wrapper').width()).toBe(selectWidth);
167+
});
168+
158169
it('should replace diacritics', function() {
159170
select.append('<option>áàãéèíìóòõúùñçÿ</option>');
160171
select.selectric('refresh');

test/fixtures/hidden.html

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<div style="display: none;" class="wrapper">
2+
<select id="select-hidden">
3+
<option value="bilberry">Bilberry</option>
4+
<option value="blackberry">Blackberry</option>
5+
<option value="blackcurrant">Blackcurrant</option>
6+
<option value="blueberry">Blueberry</option>
7+
<option value="cantaloupe">Cantaloupe</option>
8+
</select>
9+
</div>

0 commit comments

Comments
 (0)