-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
Issue #1689, change selectize behavior to work inside modals. #1813
Conversation
$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); }); |
There was a problem hiding this comment.
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.
@@ -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]) { |
There was a problem hiding this comment.
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.
@@ -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]) { |
There was a problem hiding this comment.
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.
} | ||
// Bug fix do not blur dropdown here |
There was a problem hiding this comment.
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.
Fixes selectize#1926. To be accessible, it should be possible to easily navigate elements using the keyboard. Previously, when using TAB to navigate through form elements, the input would enter its focused state when focused with TAB (and the dropdown would open when using `openOnFocus`). However, when TAB is used to jump to the next focusable element, it would not lose its focused state, and the dropdown would stay open. This commit restores the behavior before selectize#1813 and ensures that the input leaves its focused state and closes the dropdown when blurred using TAB.
Fixes selectize#1926. To be accessible, it should be possible to easily navigate elements using the keyboard. Previously, when using TAB to navigate through form elements, the input would enter its focused state when focused with TAB (and the dropdown would open when using `openOnFocus`). However, when TAB is used to jump to the next focusable element, it would not lose its focused state, and the dropdown would stay open. This commit restores the behavior before selectize#1813 and ensures that the input leaves its focused state and closes the dropdown when blurred using TAB.
Fixes selectize#1926. To be accessible, it should be possible to easily navigate elements using the keyboard. Previously, when using TAB to navigate through form elements, the input would enter its focused state when focused with TAB (and the dropdown would open when using `openOnFocus`). However, when TAB is used to jump to the next focusable element, it would not lose its focused state, and the dropdown would stay open. This commit restores the behavior before selectize#1813 and ensures that the input leaves its focused state and closes the dropdown when blurred using TAB.
Fixes selectize#1926. To be accessible, it should be possible to easily navigate elements using the keyboard. Previously, when using TAB to navigate through form elements, the input would enter its focused state when focused with TAB (and the dropdown would open when using `openOnFocus`). However, when TAB is used to jump to the next focusable element, it would not lose its focused state, and the dropdown would stay open. This commit restores the behavior before selectize#1813 and ensures that the input leaves its focused state and closes the dropdown when blurred using TAB. This commit also fixes some tests to ensure they are self-contained.
Fixes #1926. To be accessible, it should be possible to easily navigate elements using the keyboard. Previously, when using TAB to navigate through form elements, the input would enter its focused state when focused with TAB (and the dropdown would open when using `openOnFocus`). However, when TAB is used to jump to the next focusable element, it would not lose its focused state, and the dropdown would stay open. This commit restores the behavior before #1813 and ensures that the input leaves its focused state and closes the dropdown when blurred using TAB. This commit also fixes some tests to ensure they are self-contained.
Thank you for selectize.js! I am pleased to contribute this PR for your consideration.
The root cause of issue #1689 is that the drop down is being closed on the
mousedown
action, leaving themouseup
/click
event to happen outside of the control. That causes theblur
event which closes any modal that the selectize resides within.A standard HTML select control changes when the
mouseup
action is received. This PR emulates that same behavior by making the selection change when themouseup
is detected.A logic error was also discovered where it appears that the author is attempting not to blur the control if the user clicks on a dropdown item. See the code comments for discussion on this.
Finally, IE11 should no longer be supported, so a few lines were removed that were causing further issues with the drop down flashing open then closed when a click was performed outside of the control.
Thank you for your consideration. I have tested this thoroughly on Chrome, Firefox, Safari on Windows, Linux and various tablet/mobile devices and it appears to be a significant improvement to the behavior of the control.