@@ -21,7 +21,7 @@ class InputTags {
2121 this . tags = this . tags || [ ] ;
2222 this . suggestions = this . suggestions || { } ;
2323 this . displayProperty = this . displayProperty || 'text' ;
24- this . keyProperty = this . keyProperty || '' ;
24+ this . keyProperty = this . keyProperty || this . displayProperty ;
2525 this . placeholder = this . placeholder || 'Add a tag' ;
2626 this . spellcheck = this . spellcheck || true ;
2727 this . maxLength = this . maxLength || MAX_SAFE_INTEGER ;
@@ -31,7 +31,7 @@ class InputTags {
3131 }
3232
3333 track ( tag ) {
34- return tag [ this . keyProperty || this . displayProperty ] ;
34+ return tag [ this . keyProperty ] ;
3535 }
3636
3737 getTagText ( tag ) {
@@ -40,7 +40,7 @@ class InputTags {
4040
4141 isTagValid ( tag ) {
4242 const tagText = this . getTagText ( tag ) ;
43- const key = this . keyProperty || this . displayProperty ;
43+ const key = this . keyProperty ;
4444 return tagText &&
4545 this . tags . length <= this . maxLength &&
4646 ! this . tags . some ( element => element [ key ] === tag [ key ] ) ;
@@ -53,7 +53,6 @@ class InputTags {
5353
5454 if ( valid ) {
5555 this . tags . push ( tag ) ;
56-
5756 this . emit ( 'onTagAdded' , { tag} ) ;
5857 } else {
5958 this . emit ( 'onTagAddFailed' , { tag} ) ;
@@ -62,6 +61,10 @@ class InputTags {
6261 return tag ;
6362 }
6463
64+ isTagAdded ( tag ) {
65+ return this . tags . find ( eTag => eTag [ this . keyProperty ] === tag [ this . keyProperty ] ) ;
66+ }
67+
6568 removeTag ( tag ) {
6669 this . emit ( 'onTagRemoving' , { tag} ) ;
6770
0 commit comments