Skip to content

Commit 43a924b

Browse files
committed
fix an existing issue: angular-ui/ui-select#282
change mouseenter to mouseover and prevent the event in capture mode
1 parent b58fe48 commit 43a924b

File tree

3 files changed

+36
-24
lines changed

3 files changed

+36
-24
lines changed

app/scripts/directives/dropdown-items.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939

4040
choices.attr('ng-repeat', RepeatParser.getNgRepeatExpression($select.parserResult.itemName, '$select.items', $select.parserResult.trackByExp, groupByExp))
4141
.attr('ng-if', '$select.open') //Prevent unnecessary watches when dropdown is closed
42-
.attr('ng-mouseenter', '$select.setActiveItem('+$select.parserResult.itemName +')')
42+
.attr('ng-mouseover', '$select.setActiveItem('+$select.parserResult.itemName +')')
4343
.attr('ng-click', '$select.select(' + $select.parserResult.itemName + ',false,$event)');
4444

4545
var rowsInner = element.querySelectorAll('.acq-dropdown-item-row-inner');
@@ -49,13 +49,15 @@
4949

5050
$compile(element, transcludeFn)(scope); //Passing current transcludeFn to be able to append elements correctly from uisTranscludeAppend
5151

52-
scope.$on('$destroy', function(){
53-
console.log('dropdown-item directive scope destroy');
54-
});
52+
// not the same element after compile?
53+
// element.querySelectorAll('.acq-dropdown-item-row').on('mouseover', function(){
54+
// console.log('choice row mouseenter triggered');
55+
// });
56+
57+
// element.on('mouseover', function(){
58+
// console.log('dropdown-item mouseover triggered');
59+
// });
5560

56-
element.on('$destroy', function(){
57-
console.log('dropdow-item directive element destroy');
58-
});
5961
// scope.$watch('$select.search', function(newValue) {
6062
// if(newValue && !$select.open && $select.multiple) $select.activate(false, true);
6163
// // $select.activeIndex = $select.tagging.isActivated ? -1 : 0;

app/scripts/directives/dropdown-list.js

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
var ngModel = ctrls[1];
3333

3434
var searchInput = element.querySelectorAll('input.ui-select-search');
35+
var scrollFlag = false; // marks if the mouseover event is triggered by the ensureHighlightVisible function call. stopPropagation if so
3536

3637
//From view --> model
3738
ngModel.$parsers.unshift(function (inputValue) {
@@ -80,15 +81,26 @@
8081
$select.selected = ngModel.$viewValue;
8182
};
8283

84+
// element.on('focusin', function(){
85+
// console.log('focusin event on dropdown-list')
86+
// });
8387

84-
element.on('focus', function(){
85-
console.log('focus event on dropdown-list')
86-
});
88+
// element.on('mouseover', function(){
89+
// console.log('mouseover event bubble mode');
90+
// });
91+
92+
element[0].addEventListener('mouseover', function(e){
93+
console.log('mouseover event capture mode');
94+
if (scrollFlag){
95+
e.preventDefault();
96+
e.stopPropagation();
97+
}
98+
scrollFlag = false;
99+
}, true);
87100

88101
// handle key press
89102
element.on('keydown', function(e) {
90103
var key = e.which;
91-
console.log('key event on dropdown-list');
92104
scope.$apply(function() {
93105
var processed = false;
94106
if (!processed && $select.items.length > 0) {
@@ -97,14 +109,13 @@
97109
if (processed) {
98110
//TODO Check si el tab selecciona aun correctamente
99111
//Crear test
112+
console.log('processed');
100113
e.preventDefault();
101114
e.stopPropagation();
102115
}
103116
if((key === 38 || key ===40) && $select.items.length > 0){
104117
ensureHighlightVisible();
105118
}
106-
107-
108119
});
109120
});
110121

@@ -123,15 +134,15 @@
123134
}
124135
});
125136

126-
// when move the UP/DOWN, ensure that the dropdown scrolls to keep the current highlighted item in sight
137+
// when move UP/DOWN, ensure that the dropdown scrolls to keep the current highlighted item in sight
127138
function ensureHighlightVisible() {
128-
// debugger;
139+
scrollFlag = true;
129140
var container = angular.element(element[0].querySelectorAll('.acq-dropdown-item'));
130141
var choices = angular.element(container[0].querySelectorAll('.acq-dropdown-item-row'));
131-
if (choices.length < 1) {
132-
throw uiSelectMinErr('choices', "Expected multiple .ui-select-choices-row but got '{0}'.", choices.length);
133-
}
134-
142+
// if (choices.length < 1) {
143+
// throw uiSelectMinErr('choices', "Expected multiple .ui-select-choices-row but got '{0}'.", choices.length);
144+
// }
145+
// debugger;
135146
var highlighted = choices[$select.activeIndex];
136147
var posY = highlighted.offsetTop + highlighted.clientHeight - container[0].scrollTop;
137148
var height = container[0].offsetHeight;
@@ -164,12 +175,11 @@
164175
$document.on('click', onDocumentClick);
165176

166177
element.on('$destroy', function(){
167-
console.log('dropdow-list directive element destroy');
178+
168179
});
169180

170181
scope.$on('$destroy', function() {
171182
$document.off('click', onDocumentClick);
172-
console.log('dropdow-list directive scope destroy');
173183
});
174184

175185
transcludeFn(scope, function(clone) {

app/scripts/directives/dropdownListCtrl.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@
4141
ctrl.open = false;
4242

4343
var _searchInput = $element.querySelectorAll('input.ui-select-search');
44+
4445
var threshold = $element.attr('search-threshold') === undefined ? ctrl.searchThreshold : $element.attr('search-threshold');
45-
console.log(threshold);
4646

4747
ctrl.isEmpty = function () {
4848
return angular.isUndefined(ctrl.selected) || ctrl.selected === null || ctrl.selected === '';
@@ -72,7 +72,6 @@
7272
};
7373

7474
function resetSearchInput() {
75-
// console.log(ctrl.items.length);
7675
if (ctrl.resetSearchInput) {
7776
ctrl.search = '';
7877
//reset activeIndex
@@ -150,6 +149,7 @@
150149
ctrl.setActiveItem = function (item) {
151150
// debugger;
152151
// console.log(ctrl.items.length);
152+
console.log('set active item called');
153153
ctrl.activeIndex = ctrl.items.indexOf(item);
154154
};
155155

@@ -204,7 +204,7 @@
204204
break;
205205
case KEY.UP:
206206
if (!ctrl.open && ctrl.multiple) ctrl.activate(false, true); //In case its the search input in 'multiple' mode
207-
else if (ctrl.activeIndex > 0 || (ctrl.search.length === 0)) { ctrl.activeIndex--; }
207+
else if (ctrl.activeIndex > 0) { ctrl.activeIndex--; }
208208
break;
209209
case KEY.TAB:
210210
if (!ctrl.multiple || ctrl.open) ctrl.select(ctrl.items[ctrl.activeIndex], true);

0 commit comments

Comments
 (0)