Skip to content

Commit a72ad8a

Browse files
committed
autocomplete: store query string on Suggestion instance
1 parent bbf4c08 commit a72ad8a

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/converse-autocomplete.js

+11-2
Original file line numberDiff line numberDiff line change
@@ -86,16 +86,25 @@ const helpers = {
8686
}
8787

8888

89+
/**
90+
* An autocomplete suggestion
91+
*/
8992
class Suggestion extends String {
9093

91-
constructor (data) {
94+
/**
95+
* @param { Any } data - The auto-complete data. Ideally an object e.g. { label, value },
96+
* which specifies the value and human-presentable label of the suggestion.
97+
* @param { string } query - The query string being auto-completed
98+
*/
99+
constructor (data, query) {
92100
super();
93101
const o = Array.isArray(data)
94102
? { label: data[0], value: data[1] }
95103
: typeof data === "object" && "label" in data && "value" in data ? data : { label: data, value: data };
96104

97105
this.label = o.label || o.value;
98106
this.value = o.value;
107+
this.query = query;
99108
}
100109

101110
get lenth () {
@@ -381,7 +390,7 @@ export class AutoComplete {
381390
this.ul.innerHTML = "";
382391

383392
this.suggestions = list
384-
.map(item => new Suggestion(this.data(item, value)))
393+
.map(item => new Suggestion(this.data(item, value), value))
385394
.filter(item => this.filter(item, value));
386395

387396
if (this.sort !== false) {

0 commit comments

Comments
 (0)