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

Commit 5d8fb7e

Browse files
author
Brian Feister
committed
Fix incorrect initial -1 activeIndex when taggingLabel !== false
1 parent e417d20 commit 5d8fb7e

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

src/select.js

+13-5
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,12 @@
201201

202202
ctrl.activeIndex = ctrl.activeIndex >= ctrl.items.length ? 0 : ctrl.activeIndex;
203203

204+
// ensure that the index is set to zero for tagging variants
205+
// that where first option is auto-selected
206+
if ( ctrl.activeIndex === -1 && ctrl.taggingLabel !== false ) {
207+
ctrl.activeIndex = 0;
208+
}
209+
204210
// Give it time to appear before focus
205211
$timeout(function() {
206212
ctrl.search = initSearchValue || ctrl.search;
@@ -323,17 +329,15 @@
323329
var itemIndex = ctrl.items.indexOf(itemScope[ctrl.itemProperty]);
324330
var isActive = itemIndex === ctrl.activeIndex;
325331

326-
if ( !isActive || itemIndex < 0 ) {
332+
if ( !isActive || ( itemIndex < 0 && ctrl.taggingLabel !== false ) ||( itemIndex < 0 && ctrl.taggingLabel === false) ) {
327333
return false;
328334
}
335+
329336
if (isActive && !angular.isUndefined(ctrl.onHighlightCallback)) {
330337
itemScope.$eval(ctrl.onHighlightCallback);
331338
}
332339

333-
if ( ctrl.taggingLabel === false && ctrl.activeIndex === -1 ) {
334-
return false;
335-
}
336-
return itemIndex === ctrl.activeIndex;
340+
return isActive;
337341
};
338342

339343
ctrl.isDisabled = function(itemScope) {
@@ -1014,6 +1018,10 @@
10141018
$select.taggingLabel = attrs.taggingLabel !== undefined ? attrs.taggingLabel : '(new)';
10151019
}
10161020
}
1021+
else
1022+
{
1023+
$select.taggingLabel = false;
1024+
}
10171025
});
10181026

10191027
attrs.$observe('taggingTokens', function() {

0 commit comments

Comments
 (0)