Skip to content

Commit f85a6e9

Browse files
authored
Merge pull request #1813 from vanboom/master
Issue #1689, change selectize behavior to work inside modals.
2 parents bad8a95 + e579212 commit f85a6e9

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

src/selectize.js

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ $.extend(Selectize.prototype, {
136136

137137
$wrapper = $('<div>').addClass(settings.wrapperClass).addClass(classes).addClass(inputMode);
138138
$control = $('<div>').addClass(settings.inputClass).addClass('items').appendTo($wrapper);
139-
$control_input = $('<input type="text" autocomplete="new-password" autofill="no" />').appendTo($control).attr('tabindex', $input.is(':disabled') ? '-1' : self.tabIndex);
139+
$control_input = $('<input type="select-one" autocomplete="new-password" autofill="no" />').appendTo($control).attr('tabindex', $input.is(':disabled') ? '-1' : self.tabIndex);
140140
$dropdown_parent = $(settings.dropdownParent || $wrapper);
141141
$dropdown = $('<div>').addClass(settings.dropdownClass).addClass(inputMode).hide().appendTo($dropdown_parent);
142142
$dropdown_content = $('<div>').addClass(settings.dropdownContentClass).attr('tabindex', '-1').appendTo($dropdown);
@@ -191,10 +191,10 @@ $.extend(Selectize.prototype, {
191191
self.$dropdown = $dropdown;
192192
self.$dropdown_content = $dropdown_content;
193193

194-
$dropdown.on('mouseenter mousedown click', '[data-disabled]>[data-selectable]', function(e) { e.stopImmediatePropagation(); });
194+
$dropdown.on('mouseenter mousedown mouseup click', '[data-disabled]>[data-selectable]', function(e) { e.stopImmediatePropagation(); });
195195
$dropdown.on('mouseenter', '[data-selectable]', function() { return self.onOptionHover.apply(self, arguments); });
196-
$dropdown.on('mousedown click', '[data-selectable]', function() { return self.onOptionSelect.apply(self, arguments); });
197-
watchChildEvent($control, 'mousedown', '*:not(input)', function() { return self.onItemSelect.apply(self, arguments); });
196+
$dropdown.on('mouseup click', '[data-selectable]', function() { return self.onOptionSelect.apply(self, arguments); });
197+
watchChildEvent($control, 'mouseup', '*:not(input)', function() { return self.onItemSelect.apply(self, arguments); });
198198
autoGrow($control_input);
199199

200200
$control.on({
@@ -208,7 +208,7 @@ $.extend(Selectize.prototype, {
208208
keypress : function() { return self.onKeyPress.apply(self, arguments); },
209209
input : function() { return self.onInput.apply(self, arguments); },
210210
resize : function() { self.positionDropdown.apply(self, []); },
211-
blur : function() { return self.onBlur.apply(self, arguments); },
211+
// blur : function() { return self.onBlur.apply(self, arguments); },
212212
focus : function() { self.ignoreBlur = false; return self.onFocus.apply(self, arguments); },
213213
paste : function() { return self.onPaste.apply(self, arguments); }
214214
});
@@ -232,7 +232,8 @@ $.extend(Selectize.prototype, {
232232
return false;
233233
}
234234
// blur on click outside
235-
if (!self.$control.has(e.target).length && e.target !== self.$control[0]) {
235+
// do not blur if the dropdown is clicked
236+
if (!self.$dropdown.has(e.target).length && e.target !== self.$control[0]) {
236237
self.blur(e.target);
237238
}
238239
}
@@ -664,12 +665,14 @@ $.extend(Selectize.prototype, {
664665

665666
if (self.ignoreFocus) {
666667
return;
667-
} else if (!self.ignoreBlur && document.activeElement === self.$dropdown_content[0]) {
668-
// necessary to prevent IE closing the dropdown when the scrollbar is clicked
669-
self.ignoreBlur = true;
670-
self.onFocus(e);
671-
return;
672668
}
669+
// Bug fix do not blur dropdown here
670+
// else if (!self.ignoreBlur && document.activeElement === self.$dropdown_content[0]) {
671+
// // necessary to prevent IE closing the dropdown when the scrollbar is clicked
672+
// self.ignoreBlur = true;
673+
// self.onFocus(e);
674+
// return;
675+
// }
673676

674677
var deactivate = function() {
675678
self.close();

0 commit comments

Comments
 (0)