Skip to content

Commit 842e980

Browse files
committed
Merge pull request yuche#138 from petercoles/typeahead-start
Allow typeahead queries to be matched strictly to suggestion starts
2 parents 740ef06 + ce8cc73 commit 842e980

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

docs/example/typeaheadDocs.vue

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,12 @@ new Vue {
131131
<td><code>false</code></td>
132132
<td>Case sensitive for suggestions.</td>
133133
</tr>
134+
<tr>
135+
<td>match-start</td>
136+
<td><code>Boolean</code></td>
137+
<td><code>false</code></td>
138+
<td>Match only against start of suggestions. E.g. if true, "a" matches "ab" but not "ba".</td>
139+
</tr>
134140
<tr>
135141
<td>on-hit</td>
136142
<td><code>Function</code></td>

src/Typeahead.vue

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,11 @@ const typeahead = {
6161
coerce: coerceBoolean,
6262
default: false
6363
},
64+
matchStart: {
65+
type: Boolean,
66+
coerce: coerceBoolean,
67+
default: false
68+
},
6469
onHit: {
6570
type: Function,
6671
default(items) {
@@ -87,7 +92,7 @@ const typeahead = {
8792
return this.data.filter(value=> {
8893
value = this.matchCase ? value : value.toLowerCase();
8994
var query = this.matchCase ? this.query : this.query.toLowerCase();
90-
return value.indexOf(query) !== -1;
95+
return this.matchStart ? value.indexOf(query) === 0 : value.indexOf(query) !== -1;
9196
}).slice(0, this.limit)
9297
}
9398
}

0 commit comments

Comments
 (0)