Skip to content

Commit

Permalink
fix: fixes the mouse activation issue angular-ui#2160
Browse files Browse the repository at this point in the history
mouse movement changes the active index in choice list

Addresses angular-ui#2160
  • Loading branch information
Martin Kresse committed Sep 7, 2018
1 parent d8fed30 commit f653edb
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/uiSelectChoicesDirective.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,22 @@ uis.directive('uiSelectChoices',

return function link(scope, element, attrs, $select) {

var lastIndex = -1;
function mouseActivationHandler(ev) {
var row = angular.element(ev.target).closest('.ui-select-choices-row');
if (row) {
var rowScope = row.scope();
if (rowScope && angular.isDefined(rowScope.$index)) {
var newIndex = rowScope.$index;
if (newIndex !== lastIndex) {
lastIndex = newIndex;
scope.$apply(function() {
$select.activeIndex = newIndex;
});
}
}
}
}

$select.parseRepeatAttr(attrs.repeat, groupByExp, groupFilterExp); //Result ready at $select.parserResult
$select.disableChoiceExpression = attrs.uiDisableChoice;
Expand Down Expand Up @@ -80,8 +96,10 @@ uis.directive('uiSelectChoices',
if (open) {
tElement.attr('role', 'listbox');
$select.refresh(attrs.refresh);
element.on('mousemove', mouseActivationHandler);
} else {
element.removeAttr('role');
element.off('mousemove', mouseActivationHandler);
}
});
};
Expand Down

0 comments on commit f653edb

Please sign in to comment.