Skip to content

Commit 0a46193

Browse files
committed
Fix #15: Highlighted item persists when field loses focus
1 parent 0bcbc9f commit 0a46193

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

cw-token-field.html

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@
7070
},
7171

7272
onFocus: function() {
73-
this.isOptionsListVisible = true;
73+
this.resetOptionsList();
7474
},
7575

7676
onInput: function() {
@@ -91,8 +91,7 @@
9191
// Up
9292
event.preventDefault();
9393
if (!this.isOptionsListVisible) {
94-
this.isOptionsListVisible = true;
95-
this.$.optionsList.highlightFirst();
94+
this.resetOptionsList();
9695
}
9796
else {
9897
this.$.optionsList.highlightPrevious();
@@ -102,8 +101,7 @@
102101
// Down
103102
event.preventDefault();
104103
if (!this.isOptionsListVisible) {
105-
this.isOptionsListVisible = true;
106-
this.$.optionsList.highlightFirst();
104+
this.resetOptionsList();
107105
}
108106
else {
109107
this.$.optionsList.highlightNext();
@@ -113,7 +111,9 @@
113111

114112
onTap: function() {
115113
this.$.filter.focus();
116-
this.isOptionsListVisible = true;
114+
if (!this.isOptionsListVisible) {
115+
this.resetOptionsList();
116+
}
117117
},
118118

119119
placeholderChanged: function() {
@@ -125,6 +125,11 @@
125125
}
126126
},
127127

128+
resetOptionsList: function() {
129+
this.$.optionsList.highlightFirst();
130+
this.isOptionsListVisible = true;
131+
},
132+
128133
selectedChanged: function() {
129134
this.isOptionsListVisible = false;
130135
this.filterText = '';

0 commit comments

Comments
 (0)