Skip to content

Commit

Permalink
simplify not blurring control when clicking on dropdown
Browse files Browse the repository at this point in the history
Avoid control getting blurred on mousedown events on the dropdown
Fixes #1926
  • Loading branch information
YoYuUm authored and risadams committed Dec 23, 2022
1 parent 544602b commit 4b6b563
Showing 1 changed file with 6 additions and 13 deletions.
19 changes: 6 additions & 13 deletions src/selectize.js
Original file line number Diff line number Diff line change
Expand Up @@ -237,18 +237,15 @@ $.extend(Selectize.prototype, {

$document.on('mousedown' + eventNS, function(e) {
if (self.isFocused) {
// prevent events on the dropdown scrollbar from causing the control to blur
if (e.target === self.$dropdown[0] || e.target.parentNode === self.$dropdown[0]) {
// prevent events on the dropdown from causing the control to blur
if (
e.target === self.$dropdown[0] ||
self.$dropdown.has(e.target).length)
{
return false;
}
// blur on click outside
// do not blur if the dropdown is clicked
if (self.$dropdown.has(e.target).length) {
self.ignoreBlur = true;
window.setTimeout(function() {
self.ignoreBlur = false;
}, 0);
} else if (e.target !== self.$control[0]) {
if (e.target !== self.$control[0]) {
self.blur(e.target);
}
}
Expand Down Expand Up @@ -691,10 +688,6 @@ $.extend(Selectize.prototype, {
onBlur: function(e, dest) {
var self = this;

if (self.ignoreBlur) {
return;
}

if (!self.isFocused) return;
self.isFocused = false;

Expand Down

0 comments on commit 4b6b563

Please sign in to comment.