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

Commit

Permalink
fix(uiSelectCtrl): correcting input focus
Browse files Browse the repository at this point in the history
Corrected input focus when ui-select contains no elements. Also corrected a memory leaked caused by event handlers never being removed.

Closes #1253
  • Loading branch information
patrickhousley committed Mar 23, 2016
1 parent dfa0969 commit 6444d6b
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions src/uiSelectController.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 6444d6b

Please sign in to comment.