Skip to content
This repository was archived by the owner on Oct 2, 2019. It is now read-only.

Commit 6f19d5f

Browse files
committed
fix(drop-down): close drop-down regardless of stopPropagation() calls
As of now, an event-handler on the `document` is responsible for closing the drop-down. A click-event stops bubbling when `stopPropagation()` is called, therefor it breaks the closing of the drop-down. Registering the event-listener in capture phase fixes this bug.
1 parent 2f10304 commit 6f19d5f

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

src/uiSelectDirective.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
uis.directive('uiSelect',
2-
['$document', 'uiSelectConfig', 'uiSelectMinErr', 'uisOffset', '$compile', '$parse', '$timeout',
3-
function($document, uiSelectConfig, uiSelectMinErr, uisOffset, $compile, $parse, $timeout) {
2+
['$document', 'uiSelectConfig', 'uiSelectMinErr', 'uisOffset', '$compile', '$parse', '$timeout', '$window',
3+
function($document, uiSelectConfig, uiSelectMinErr, uisOffset, $compile, $parse, $timeout, $window) {
44

55
return {
66
restrict: 'EA',
@@ -206,11 +206,15 @@ uis.directive('uiSelect',
206206
$select.clickTriggeredSelect = false;
207207
}
208208

209-
// See Click everywhere but here event http://stackoverflow.com/questions/12931369
210-
$document.on('click', onDocumentClick);
209+
// See Click everywhere but here. Similar approach to http://stackoverflow.com/questions/12931369
210+
// but using the capture phase instead of bubble phase of the event propagation.
211+
//
212+
// Using the capture phase avoids problems that araise when event.stopPropatagion()
213+
// is called before the event reaches the `document`.
214+
$window.document.addEventListener('click', onDocumentClick, true);
211215

212216
scope.$on('$destroy', function() {
213-
$document.off('click', onDocumentClick);
217+
$window.document.removeEventListener('click', onDocumentClick, true);
214218
});
215219

216220
// Move transcluded elements to their correct position in main template

0 commit comments

Comments
 (0)