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

Commit 8da8a6d

Browse files
committed
feat(ngAnimate): add support for ngAnimate
Merge branch 'patrickhousley-issue-859'
2 parents e7b4c52 + fa61cae commit 8da8a6d

File tree

1 file changed

+38
-13
lines changed

1 file changed

+38
-13
lines changed

src/uiSelectController.js

Lines changed: 38 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
* put as much logic in the controller (instead of the link functions) as possible so it can be easily tested.
66
*/
77
uis.controller('uiSelectCtrl',
8-
['$scope', '$element', '$timeout', '$filter', 'uisRepeatParser', 'uiSelectMinErr', 'uiSelectConfig', '$parse',
9-
function($scope, $element, $timeout, $filter, RepeatParser, uiSelectMinErr, uiSelectConfig, $parse) {
8+
['$scope', '$element', '$timeout', '$filter', 'uisRepeatParser', 'uiSelectMinErr', 'uiSelectConfig', '$parse', '$injector',
9+
function($scope, $element, $timeout, $filter, RepeatParser, uiSelectMinErr, uiSelectConfig, $parse, $injector) {
1010

1111
var ctrl = this;
1212

@@ -41,11 +41,21 @@ uis.controller('uiSelectCtrl',
4141
ctrl.clickTriggeredSelect = false;
4242
ctrl.$filter = $filter;
4343

44+
// Use $injector to check for $animate and store a reference to it
45+
ctrl.$animate = (function () {
46+
try {
47+
return $injector.get('$animate');
48+
} catch (err) {
49+
// $animate does not exist
50+
return null;
51+
}
52+
})();
53+
4454
ctrl.searchInput = $element.querySelectorAll('input.ui-select-search');
4555
if (ctrl.searchInput.length !== 1) {
4656
throw uiSelectMinErr('searchInput', "Expected 1 input.ui-select-search but got '{0}'.", ctrl.searchInput.length);
4757
}
48-
58+
4959
ctrl.isEmpty = function() {
5060
return angular.isUndefined(ctrl.selected) || ctrl.selected === null || ctrl.selected === '';
5161
};
@@ -90,14 +100,29 @@ uis.controller('uiSelectCtrl',
90100
ctrl.activeIndex = 0;
91101
}
92102

93-
// Give it time to appear before focus
94-
$timeout(function() {
95-
ctrl.search = initSearchValue || ctrl.search;
96-
ctrl.searchInput[0].focus();
97-
if(!ctrl.tagging.isActivated && ctrl.items.length > 1) {
98-
_ensureHighlightVisible();
99-
}
100-
});
103+
var container = $element.querySelectorAll('.ui-select-choices-content');
104+
if (ctrl.$animate && ctrl.$animate.enabled(container[0])) {
105+
ctrl.$animate.on('enter', container[0], function (elem, phase) {
106+
if (phase === 'close') {
107+
// Only focus input after the animation has finished
108+
$timeout(function () {
109+
ctrl.focusSearchInput(initSearchValue);
110+
});
111+
}
112+
});
113+
} else {
114+
$timeout(function () {
115+
ctrl.focusSearchInput(initSearchValue);
116+
});
117+
}
118+
}
119+
};
120+
121+
ctrl.focusSearchInput = function (initSearchValue) {
122+
ctrl.search = initSearchValue || ctrl.search;
123+
ctrl.searchInput[0].focus();
124+
if(!ctrl.tagging.isActivated && ctrl.items.length > 1) {
125+
_ensureHighlightVisible();
101126
}
102127
};
103128

@@ -149,7 +174,7 @@ uis.controller('uiSelectCtrl',
149174
//If collection is an Object, convert it to Array
150175

151176
var originalSource = ctrl.parserResult.source;
152-
177+
153178
//When an object is used as source, we better create an array and use it as 'source'
154179
var createArrayFromObject = function(){
155180
var origSrc = originalSource($scope);
@@ -195,7 +220,7 @@ uis.controller('uiSelectCtrl',
195220
ctrl.items = [];
196221
} else {
197222
if (!angular.isArray(items)) {
198-
throw uiSelectMinErr('items', "Expected an array but got '{0}'.", items);
223+
throw uiSelectMinErr('items', "Expected an array but got '{0}'.", items);
199224
} else {
200225
//Remove already selected items (ex: while searching)
201226
//TODO Should add a test

0 commit comments

Comments
 (0)