Commit a72ad8a5 authored by JC Brand's avatar JC Brand

autocomplete: store query string on Suggestion instance

parent bbf4c08f
...@@ -86,9 +86,17 @@ const helpers = { ...@@ -86,9 +86,17 @@ const helpers = {
} }
/**
* An autocomplete suggestion
*/
class Suggestion extends String { class Suggestion extends String {
constructor (data) { /**
* @param { Any } data - The auto-complete data. Ideally an object e.g. { label, value },
* which specifies the value and human-presentable label of the suggestion.
* @param { string } query - The query string being auto-completed
*/
constructor (data, query) {
super(); super();
const o = Array.isArray(data) const o = Array.isArray(data)
? { label: data[0], value: data[1] } ? { label: data[0], value: data[1] }
...@@ -96,6 +104,7 @@ class Suggestion extends String { ...@@ -96,6 +104,7 @@ class Suggestion extends String {
this.label = o.label || o.value; this.label = o.label || o.value;
this.value = o.value; this.value = o.value;
this.query = query;
} }
get lenth () { get lenth () {
...@@ -381,7 +390,7 @@ export class AutoComplete { ...@@ -381,7 +390,7 @@ export class AutoComplete {
this.ul.innerHTML = ""; this.ul.innerHTML = "";
this.suggestions = list this.suggestions = list
.map(item => new Suggestion(this.data(item, value))) .map(item => new Suggestion(this.data(item, value), value))
.filter(item => this.filter(item, value)); .filter(item => this.filter(item, value));
if (this.sort !== false) { if (this.sort !== false) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment