Skip to content

Issue #1653 implement a minwidth setting to improve responsive situations #1814

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 2 commits 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
33 changes: 20 additions & 13 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); });
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]) {
// do not blur if the dropdown is clicked
if (!self.$dropdown.has(e.target).length && e.target !== self.$control[0]) {
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
// 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 Expand Up @@ -1916,9 +1919,13 @@ $.extend(Selectize.prototype, {
var $control = this.$control;
var offset = this.settings.dropdownParent === 'body' ? $control.offset() : $control.position();
offset.top += $control.outerHeight(true);

var w = $control[0].getBoundingClientRect().width;
if (this.settings.minWidth && this.settings.minWidth > w)
{
w = this.settings.minWidth;
}
this.$dropdown.css({
width : $control[0].getBoundingClientRect().width,
width : w,
top : offset.top,
left : offset.left
});
Expand Down