Skip to content

Commit f5d714a

Browse files
authored
several fix and enhancements (#1906)
* fix: style dropdown bootstrap4/5 * fix: appareance with input-group class * feat: add ignoreOnDropdownHeight property * fix: calcul dropdownheight with optgroup * fix: style for input-group class * fix: add separator height to dropdown height calcul * feat: add option 'search' * test: add test for normalize/search options * fix: different style for select/active option * fix: persitant state style for selected item * fix: peristant style for selected option * fix: prevent the keyboard on mobile devices
1 parent 810c7bd commit f5d714a

File tree

5 files changed

+78
-28
lines changed

5 files changed

+78
-28
lines changed

src/defaults.js

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -61,26 +61,27 @@ Selectize.defaults = {
6161
},
6262
normalize: false,
6363
ignoreOnDropwdownHeight: 'img, i',
64-
/*
65-
load : null, // function(query, callback) { ... }
66-
score : null, // function(search) { ... }
67-
formatValueToKey : null, // function(key) { ... }
68-
onInitialize : null, // function() { ... }
69-
onChange : null, // function(value) { ... }
70-
onItemAdd : null, // function(value, $item) { ... }
71-
onItemRemove : null, // function(value, $item) { ... }
72-
onClear : null, // function() { ... }
73-
onOptionAdd : null, // function(value, data) { ... }
74-
onOptionRemove : null, // function(value) { ... }
75-
onOptionClear : null, // function() { ... }
76-
onOptionGroupAdd : null, // function(id, data) { ... }
77-
onOptionGroupRemove : null, // function(id) { ... }
78-
onOptionGroupClear : null, // function() { ... }
79-
onDropdownOpen : null, // function($dropdown) { ... }
80-
onDropdownClose : null, // function($dropdown) { ... }
81-
onType : null, // function(str) { ... }
82-
onDelete : null, // function(values) { ... }
83-
*/
64+
search: true,
65+
/*
66+
load : null, // function(query, callback) { ... }
67+
score : null, // function(search) { ... }
68+
formatValueToKey : null, // function(key) { ... }
69+
onInitialize : null, // function() { ... }
70+
onChange : null, // function(value) { ... }
71+
onItemAdd : null, // function(value, $item) { ... }
72+
onItemRemove : null, // function(value, $item) { ... }
73+
onClear : null, // function() { ... }
74+
onOptionAdd : null, // function(value, data) { ... }
75+
onOptionRemove : null, // function(value) { ... }
76+
onOptionClear : null, // function() { ... }
77+
onOptionGroupAdd : null, // function(id, data) { ... }
78+
onOptionGroupRemove : null, // function(id) { ... }
79+
onOptionGroupClear : null, // function() { ... }
80+
onDropdownOpen : null, // function($dropdown) { ... }
81+
onDropdownClose : null, // function($dropdown) { ... }
82+
onType : null, // function(str) { ... }
83+
onDelete : null, // function(values) { ... }
84+
*/
8485

8586
render: {
8687
/*

src/scss/selectize.scss

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -270,15 +270,25 @@ $select-spinner-border-color: $select-color-border;
270270
cursor: default;
271271
}
272272
.active {
273-
background-color: $select-color-dropdown-item-active;
274-
color: $select-color-dropdown-item-active-text;
273+
background-color: $select-color-item-active;
274+
color: $select-color-item-active-text;
275275
&.create {
276276
color: $select-color-dropdown-item-create-active-text;
277277
}
278278
}
279+
280+
.selected {
281+
background-color: $select-color-item-active;
282+
color: $select-color-item-active-text;
283+
}
279284
.create {
280285
color: $select-color-dropdown-item-create-text;
281286
}
287+
288+
.active:not(.selected) {
289+
background: $select-color-dropdown-item-active;
290+
color: $select-color-dropdown-item-active-text;
291+
}
282292
}
283293

284294
.#{$selectize}-dropdown-content {
@@ -326,7 +336,7 @@ $select-spinner-border-color: $select-color-border;
326336
cursor: pointer;
327337
}
328338
&.input-active,
329-
&.input-active input {
339+
&.input-active input:not(:read-only) {
330340
cursor: text;
331341
}
332342

src/selectize.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,13 @@ $.extend(Selectize.prototype, {
158158
$control_input.attr('placeholder', settings.placeholder);
159159
}
160160

161+
// to have an identical rendering to a simple select (usefull for mobile device and do not open keyboard)
162+
if (!self.settings.search) {
163+
$control_input.attr('readonly', true);
164+
$control_input.attr('inputmode', 'none');
165+
$control.css('cursor', 'pointer');
166+
}
167+
161168
// if splitOn was not passed in, construct it from the delimiter to allow pasting universally
162169
if (!self.settings.splitOn && self.settings.delimiter) {
163170
var delimiterEscaped = self.settings.delimiter.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&');

test/api.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -632,6 +632,23 @@
632632
});
633633
test.selectize.search('hello');
634634
}).to.not.throw(Error);
635+
});
636+
it('should normalize a string', function () {
637+
var test;
638+
639+
beforeEach(function() {
640+
test = setup_test('<select>' +
641+
'<option value="a">A</option>' +
642+
'</select>', { normalize: true });
643+
});
644+
645+
it('should return query satinized', function() {
646+
var query = test.selectize.search('héllo').query;
647+
648+
window.setTimeout(function () {
649+
expect(query).to.be.equal('hello');
650+
}, 0);
651+
});
635652
});
636653
});
637654

test/setup.js

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -217,12 +217,10 @@
217217
beforeEach(function() {
218218
test = setup_test('<select>' +
219219
'<option value="a" style="color:red;" class="a">A</option>' +
220-
'</select>', {
221-
dropdownSize: { sizeType: 'fixedHeight', sizeValue: 100 }
222-
});
220+
'</select>');
223221
});
224222

225-
it('should dropdown height to be equal 100', function(done) {
223+
it('should dropdown height to be equal 100', function() {
226224
test.selectize.focus();
227225

228226
window.setTimeout(function () {
@@ -231,6 +229,24 @@
231229
}, 0);
232230
});
233231
});
232+
233+
it('should respect input readonly (option search = false)', function () {
234+
var test;
235+
236+
beforeEach(function() {
237+
test = setup_test('<select>' +
238+
'<option value="a">A</option>' +
239+
'</select>', { search: false });
240+
});
241+
242+
it('should readonly on input and cursor pointer on input and control element', function () {
243+
window.setTimeout(function () {
244+
expect(test.selectize.$dropdown_input.attr('readonly')).to.be.equal('readonly');
245+
expect(test.selectize.$dropdown_input.css('cursor')).to.be.equal('pointer');
246+
expect(test.selectize.$control.css('cursor')).to.be.equal('pointer');
247+
}, 0);
248+
});
249+
});
234250
describe('getValue()', function() {
235251
it('should return "" when empty', function() {
236252
var test = setup_test('<select>', {});
@@ -470,7 +486,6 @@
470486
}, 0);
471487
});
472488
});
473-
474489
});
475490

476491
})();

0 commit comments

Comments
 (0)