Skip to content

Commit 8792569

Browse files
committed
Merge branch 'master' into feature/#90-retain-mobile-dropdown
2 parents afb33c1 + dbfcdca commit 8792569

File tree

5 files changed

+29
-3
lines changed

5 files changed

+29
-3
lines changed

public/jquery.selectric.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,8 +291,11 @@
291291
/** Activates the plugin */
292292
activate: function() {
293293
var _this = this;
294+
var hiddenChildren = _this.elements.items.closest(':visible').children(':hidden').addClass(_this.classes.tempshow);
294295
var originalWidth = _this.$element.width();
295296

297+
hiddenChildren.removeClass(_this.classes.tempshow);
298+
296299
_this.utils.triggerCallback('BeforeActivate', _this);
297300

298301
_this.elements.outerWrapper.prop('class',
@@ -485,7 +488,7 @@
485488
value : $elm.val(),
486489
className : $elm.prop('class'),
487490
text : $elm.html(),
488-
slug : _this.utils.replaceDiacritics($elm.html()),
491+
slug : $.trim(_this.utils.replaceDiacritics($elm.html())),
489492
selected : $elm.prop('selected'),
490493
disabled : isDisabled
491494
};

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: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,8 +274,11 @@
274274
/** Activates the plugin */
275275
activate: function() {
276276
var _this = this;
277+
var hiddenChildren = _this.elements.items.closest(':visible').children(':hidden').addClass(_this.classes.tempshow);
277278
var originalWidth = _this.$element.width();
278279

280+
hiddenChildren.removeClass(_this.classes.tempshow);
281+
279282
_this.utils.triggerCallback('BeforeActivate', _this);
280283

281284
_this.elements.outerWrapper.prop('class',
@@ -468,7 +471,7 @@
468471
value : $elm.val(),
469472
className : $elm.prop('class'),
470473
text : $elm.html(),
471-
slug : _this.utils.replaceDiacritics($elm.html()),
474+
slug : $.trim(_this.utils.replaceDiacritics($elm.html())),
472475
selected : $elm.prop('selected'),
473476
disabled : isDisabled
474477
};

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)