Skip to content

Issue #1689, change selectize behavior to work inside modals. #1813

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 16, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 14 additions & 11 deletions src/selectize.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ $.extend(Selectize.prototype, {

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

$dropdown.on('mouseenter mousedown click', '[data-disabled]>[data-selectable]', function(e) { e.stopImmediatePropagation(); });
$dropdown.on('mouseenter mousedown mouseup click', '[data-disabled]>[data-selectable]', function(e) { e.stopImmediatePropagation(); });
$dropdown.on('mouseenter', '[data-selectable]', function() { return self.onOptionHover.apply(self, arguments); });
$dropdown.on('mousedown click', '[data-selectable]', function() { return self.onOptionSelect.apply(self, arguments); });
watchChildEvent($control, 'mousedown', '*:not(input)', function() { return self.onItemSelect.apply(self, arguments); });
$dropdown.on('mouseup click', '[data-selectable]', function() { return self.onOptionSelect.apply(self, arguments); });
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Native selects change on the mouse-up. Selectize should match this behavior.

watchChildEvent($control, 'mouseup', '*:not(input)', function() { return self.onItemSelect.apply(self, arguments); });
autoGrow($control_input);

$control.on({
Expand All @@ -207,7 +207,7 @@ $.extend(Selectize.prototype, {
keypress : function() { return self.onKeyPress.apply(self, arguments); },
input : function() { return self.onInput.apply(self, arguments); },
resize : function() { self.positionDropdown.apply(self, []); },
blur : function() { return self.onBlur.apply(self, arguments); },
// blur : function() { return self.onBlur.apply(self, arguments); },
focus : function() { self.ignoreBlur = false; return self.onFocus.apply(self, arguments); },
paste : function() { return self.onPaste.apply(self, arguments); }
});
Expand All @@ -231,7 +231,8 @@ $.extend(Selectize.prototype, {
return false;
}
// blur on click outside
if (!self.$control.has(e.target).length && e.target !== self.$control[0]) {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$control will never have e.target here, as e.target is contained within $dropdown. This appears to be a logic error. When clicking inside of the dropdown we do not want to blur, so $dropdown.has(e.target) is the correct logic here.

// do not blur if the dropdown is clicked
if (!self.$dropdown.has(e.target).length && e.target !== self.$control[0]) {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

e.target is always contained within self.$dropdown here. $dropdown and $control are sibling elements in the DOM. $dropdown is the correct element to use for this logic.

self.blur(e.target);
}
}
Expand Down Expand Up @@ -648,12 +649,14 @@ $.extend(Selectize.prototype, {

if (self.ignoreFocus) {
return;
} else if (!self.ignoreBlur && document.activeElement === self.$dropdown_content[0]) {
// necessary to prevent IE closing the dropdown when the scrollbar is clicked
self.ignoreBlur = true;
self.onFocus(e);
return;
}
// Bug fix do not blur dropdown here
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code causes the drop down to flash open then closed when a click is detected outside of the control. Let's remove it - nobody uses IE11 any more.

// else if (!self.ignoreBlur && document.activeElement === self.$dropdown_content[0]) {
// // necessary to prevent IE closing the dropdown when the scrollbar is clicked
// self.ignoreBlur = true;
// self.onFocus(e);
// return;
// }

var deactivate = function() {
self.close();
Expand Down