@@ -123,15 +123,29 @@ uis.controller('uiSelectCtrl',
123
123
}
124
124
125
125
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 ) {
129
130
// Only focus input after the animation has finished
130
131
$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 ) ;
131
139
ctrl . focusSearchInput ( initSearchValue ) ;
132
140
} ) ;
133
141
}
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
+ }
135
149
} else {
136
150
$timeout ( function ( ) {
137
151
ctrl . focusSearchInput ( initSearchValue ) ;
0 commit comments