From 6444d6b8f9e3ff3f201deeecd0ded38498d7b18d Mon Sep 17 00:00:00 2001 From: Patrick Housley Date: Wed, 23 Mar 2016 01:39:20 -0500 Subject: [PATCH 1/2] fix(uiSelectCtrl): correcting input focus Corrected input focus when ui-select contains no elements. Also corrected a memory leaked caused by event handlers never being removed. Closes #1253 --- src/uiSelectController.js | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/src/uiSelectController.js b/src/uiSelectController.js index 38c4ba0b9..43e63353b 100644 --- a/src/uiSelectController.js +++ b/src/uiSelectController.js @@ -123,15 +123,29 @@ uis.controller('uiSelectCtrl', } var container = $element.querySelectorAll('.ui-select-choices-content'); - if (ctrl.$animate && ctrl.$animate.on && ctrl.$animate.enabled(container[0])) { - ctrl.$animate.on('enter', container[0], function (elem, phase) { - if (phase === 'close') { + var searchInput = $element.querySelectorAll('.ui-select-search'); + if (ctrl.$animate && ctrl.$animate.enabled(container[0])) { + var animateHandler = function(elem, phase) { + if (phase === 'start' && ctrl.items.length === 0) { // Only focus input after the animation has finished $timeout(function () { + ctrl.$animate.off('removeClass', searchInput[0], animateHandler); + ctrl.focusSearchInput(initSearchValue); + }); + } else if (phase === 'close') { + // Only focus input after the animation has finished + $timeout(function () { + ctrl.$animate.off('enter', container[0], animateHandler); ctrl.focusSearchInput(initSearchValue); }); } - }); + }; + + if (ctrl.items.length > 0) { + ctrl.$animate.on('enter', container[0], animateHandler); + } else { + ctrl.$animate.on('removeClass', searchInput[0], animateHandler); + } } else { $timeout(function () { ctrl.focusSearchInput(initSearchValue); From 926f4628e1f7e83229a1dd1608e946e9e9322088 Mon Sep 17 00:00:00 2001 From: Patrick Housley Date: Wed, 23 Mar 2016 18:50:02 -0500 Subject: [PATCH 2/2] perf(uiSelectCtrl): moving activate events out of $timeout Moved the removal of activate events out of the $timeout. This removes additional unneccessary calls to the event handler once the $timeout has been initiated. --- src/uiSelectController.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/uiSelectController.js b/src/uiSelectController.js index 43e63353b..481fbb2e8 100644 --- a/src/uiSelectController.js +++ b/src/uiSelectController.js @@ -128,14 +128,14 @@ uis.controller('uiSelectCtrl', var animateHandler = function(elem, phase) { if (phase === 'start' && ctrl.items.length === 0) { // Only focus input after the animation has finished + ctrl.$animate.off('removeClass', searchInput[0], animateHandler); $timeout(function () { - ctrl.$animate.off('removeClass', searchInput[0], animateHandler); ctrl.focusSearchInput(initSearchValue); }); } else if (phase === 'close') { // Only focus input after the animation has finished + ctrl.$animate.off('enter', container[0], animateHandler); $timeout(function () { - ctrl.$animate.off('enter', container[0], animateHandler); ctrl.focusSearchInput(initSearchValue); }); }