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

Commit 2cc07dc

Browse files
committed
Merge pull request #1517 from patrickhousley/issue-1253
fix(uiSelectCtrl): correcting input focus
2 parents c8d47cc + 926f462 commit 2cc07dc

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

src/uiSelectController.js

Lines changed: 18 additions & 4 deletions
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
131+
ctrl.$animate.off('removeClass', searchInput[0], animateHandler);
132+
$timeout(function () {
133+
ctrl.focusSearchInput(initSearchValue);
134+
});
135+
} else if (phase === 'close') {
136+
// Only focus input after the animation has finished
137+
ctrl.$animate.off('enter', container[0], animateHandler);
130138
$timeout(function () {
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)