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

fix(uiSelectCtrl): correcting input focus #1517

Merged
merged 2 commits into from
Mar 27, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
ctrl.$animate.off('removeClass', searchInput[0], animateHandler);
$timeout(function () {
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.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