From f653edb65e509afa5d503d698de51d20a0cdd3a3 Mon Sep 17 00:00:00 2001 From: Martin Kresse Date: Fri, 7 Sep 2018 18:11:13 +0200 Subject: [PATCH] fix: fixes the mouse activation issue #2160 mouse movement changes the active index in choice list Addresses #2160 --- src/uiSelectChoicesDirective.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/uiSelectChoicesDirective.js b/src/uiSelectChoicesDirective.js index bbe8c88c3..1c417a092 100644 --- a/src/uiSelectChoicesDirective.js +++ b/src/uiSelectChoicesDirective.js @@ -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; @@ -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); } }); };