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

Commit 6444d6b

Browse files
author
Patrick Housley
committed
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
1 parent dfa0969 commit 6444d6b

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

src/uiSelectController.js

+18-4
Original file line numberDiff line numberDiff line change
@@ -123,15 +123,29 @@ uis.controller('uiSelectCtrl',
123123
}
124124

125125
var container = $element.querySelectorAll('.ui-select-choices-content');
126-
if (ctrl.$animate && ctrl.$animate.on && ctrl.$animate.enabled(container[0])) {
127-
ctrl.$animate.on('enter', container[0], function (elem, phase) {
128-
if (phase === 'close') {
126+
var searchInput = $element.querySelectorAll('.ui-select-search');
127+
if (ctrl.$animate && ctrl.$animate.enabled(container[0])) {
128+
var animateHandler = function(elem, phase) {
129+
if (phase === 'start' && ctrl.items.length === 0) {
129130
// Only focus input after the animation has finished
130131
$timeout(function () {
132+
ctrl.$animate.off('removeClass', searchInput[0], animateHandler);
133+
ctrl.focusSearchInput(initSearchValue);
134+
});
135+
} else if (phase === 'close') {
136+
// Only focus input after the animation has finished
137+
$timeout(function () {
138+
ctrl.$animate.off('enter', container[0], animateHandler);
131139
ctrl.focusSearchInput(initSearchValue);
132140
});
133141
}
134-
});
142+
};
143+
144+
if (ctrl.items.length > 0) {
145+
ctrl.$animate.on('enter', container[0], animateHandler);
146+
} else {
147+
ctrl.$animate.on('removeClass', searchInput[0], animateHandler);
148+
}
135149
} else {
136150
$timeout(function () {
137151
ctrl.focusSearchInput(initSearchValue);

0 commit comments

Comments
 (0)