1
- uis . directive ( 'uisMultiple' , [ 'uiSelectMinErr' , function ( uiSelectMinErr ) {
1
+ uis . directive ( 'uisMultiple' , [ 'uiSelectMinErr' , '$timeout' , function ( uiSelectMinErr , $timeout ) {
2
2
return {
3
3
restrict : 'EA' ,
4
4
require : [ '^uiSelect' , '^ngModel' ] ,
@@ -8,6 +8,8 @@ uis.directive('uisMultiple', ['uiSelectMinErr', function(uiSelectMinErr) {
8
8
var ctrl = this ;
9
9
var $select = $scope . $select ;
10
10
11
+ ctrl . activeMatchIndex = - 1 ;
12
+
11
13
// Remove item from multiple select
12
14
ctrl . removeChoice = function ( index ) {
13
15
@@ -20,7 +22,7 @@ uis.directive('uisMultiple', ['uiSelectMinErr', function(uiSelectMinErr) {
20
22
locals [ $select . parserResult . itemName ] = removedChoice ;
21
23
22
24
$select . selected . splice ( index , 1 ) ;
23
- $select . activeMatchIndex = - 1 ;
25
+ ctrl . activeMatchIndex = - 1 ;
24
26
$select . sizeSearchInput ( ) ;
25
27
26
28
// Give some time for scope propagation.
@@ -150,7 +152,7 @@ uis.directive('uisMultiple', ['uiSelectMinErr', function(uiSelectMinErr) {
150
152
} ) ;
151
153
152
154
scope . $on ( 'uis:activate' , function ( ) {
153
- $select . activeMatchIndex = - 1 ;
155
+ $selectMultiple . activeMatchIndex = - 1 ;
154
156
} ) ;
155
157
156
158
scope . $watch ( '$select.disabled' , function ( newValue , oldValue ) {
@@ -186,9 +188,9 @@ uis.directive('uisMultiple', ['uiSelectMinErr', function(uiSelectMinErr) {
186
188
// none = -1,
187
189
first = 0 ,
188
190
last = length - 1 ,
189
- curr = $select . activeMatchIndex ,
190
- next = $select . activeMatchIndex + 1 ,
191
- prev = $select . activeMatchIndex - 1 ,
191
+ curr = $selectMultiple . activeMatchIndex ,
192
+ next = $selectMultiple . activeMatchIndex + 1 ,
193
+ prev = $selectMultiple . activeMatchIndex - 1 ,
192
194
newIndex = curr ;
193
195
194
196
if ( caretPosition > 0 || ( $select . search . length && key == KEY . RIGHT ) ) return false ;
@@ -199,13 +201,13 @@ uis.directive('uisMultiple', ['uiSelectMinErr', function(uiSelectMinErr) {
199
201
switch ( key ) {
200
202
case KEY . LEFT :
201
203
// Select previous/first item
202
- if ( ~ $select . activeMatchIndex ) return prev ;
204
+ if ( ~ $selectMultiple . activeMatchIndex ) return prev ;
203
205
// Select last item
204
206
else return last ;
205
207
break ;
206
208
case KEY . RIGHT :
207
209
// Open drop-down
208
- if ( ! ~ $select . activeMatchIndex || curr === last ) {
210
+ if ( ! ~ $selectMultiple . activeMatchIndex || curr === last ) {
209
211
$select . activate ( ) ;
210
212
return false ;
211
213
}
@@ -214,7 +216,7 @@ uis.directive('uisMultiple', ['uiSelectMinErr', function(uiSelectMinErr) {
214
216
break ;
215
217
case KEY . BACKSPACE :
216
218
// Remove selected item and select previous/first
217
- if ( ~ $select . activeMatchIndex ) {
219
+ if ( ~ $selectMultiple . activeMatchIndex ) {
218
220
$selectMultiple . removeChoice ( curr ) ;
219
221
return prev ;
220
222
}
@@ -223,8 +225,8 @@ uis.directive('uisMultiple', ['uiSelectMinErr', function(uiSelectMinErr) {
223
225
break ;
224
226
case KEY . DELETE :
225
227
// Remove selected item and select next item
226
- if ( ~ $select . activeMatchIndex ) {
227
- $selectMultiple . removeChoice ( $select . activeMatchIndex ) ;
228
+ if ( ~ $selectMultiple . activeMatchIndex ) {
229
+ $selectMultiple . removeChoice ( $selectMultiple . activeMatchIndex ) ;
228
230
return curr ;
229
231
}
230
232
else return false ;
@@ -233,8 +235,8 @@ uis.directive('uisMultiple', ['uiSelectMinErr', function(uiSelectMinErr) {
233
235
234
236
newIndex = getNewActiveMatchIndex ( ) ;
235
237
236
- if ( ! $select . selected . length || newIndex === false ) $select . activeMatchIndex = - 1 ;
237
- else $select . activeMatchIndex = Math . min ( last , Math . max ( first , newIndex ) ) ;
238
+ if ( ! $select . selected . length || newIndex === false ) $selectMultiple . activeMatchIndex = - 1 ;
239
+ else $selectMultiple . activeMatchIndex = Math . min ( last , Math . max ( first , newIndex ) ) ;
238
240
239
241
return true ;
240
242
}
@@ -380,6 +382,11 @@ uis.directive('uisMultiple', ['uiSelectMinErr', function(uiSelectMinErr) {
380
382
return dupeIndex ;
381
383
}
382
384
385
+ $select . searchInput . on ( 'blur' , function ( ) {
386
+ $timeout ( function ( ) {
387
+ $selectMultiple . activeMatchIndex = - 1 ;
388
+ } ) ;
389
+ } ) ;
383
390
384
391
}
385
392
} ;
0 commit comments