From 1480e9a59b82c96ea2b3b3cfc242aa3666af63d1 Mon Sep 17 00:00:00 2001 From: Marcel Veldhuizen Date: Mon, 14 Nov 2016 16:43:06 +0100 Subject: [PATCH] Fix dropdown closing on scroll bar click (#1004) --- src/selectize.js | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/selectize.js b/src/selectize.js index f11553d0c..470ca3e68 100644 --- a/src/selectize.js +++ b/src/selectize.js @@ -31,7 +31,6 @@ var Selectize = function($input, settings) { isCmdDown : false, isCtrlDown : false, ignoreFocus : false, - ignoreBlur : false, ignoreHover : false, hasOptions : false, currentResults : null, @@ -202,7 +201,7 @@ $.extend(Selectize.prototype, { keypress : function() { return self.onKeyPress.apply(self, arguments); }, resize : function() { self.positionDropdown.apply(self, []); }, blur : function() { return self.onBlur.apply(self, arguments); }, - focus : function() { self.ignoreBlur = false; return self.onFocus.apply(self, arguments); }, + focus : function() { return self.onFocus.apply(self, arguments); }, paste : function() { return self.onPaste.apply(self, arguments); } }); @@ -226,7 +225,7 @@ $.extend(Selectize.prototype, { } // blur on click outside if (!self.$control.has(e.target).length && e.target !== self.$control[0]) { - self.blur(e.target); + self.close(); } } }); @@ -625,16 +624,22 @@ $.extend(Selectize.prototype, { */ onBlur: function(e, dest) { var self = this; + + if (document.activeElement === self.$dropdown_content[0]) { + // necessary to prevent IE closing the dropdown when the scrollbar is clicked + if (e) { + e.preventDefault(); + e.stopImmediatePropagation(); + } + self.onFocus(e); + return; + } + if (!self.isFocused) return; self.isFocused = false; 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; } var deactivate = function() {