File tree 1 file changed +11
-2
lines changed
1 file changed +11
-2
lines changed Original file line number Diff line number Diff line change @@ -86,16 +86,25 @@ const helpers = {
86
86
}
87
87
88
88
89
+ /**
90
+ * An autocomplete suggestion
91
+ */
89
92
class Suggestion extends String {
90
93
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 ) {
92
100
super ( ) ;
93
101
const o = Array . isArray ( data )
94
102
? { label : data [ 0 ] , value : data [ 1 ] }
95
103
: typeof data === "object" && "label" in data && "value" in data ? data : { label : data , value : data } ;
96
104
97
105
this . label = o . label || o . value ;
98
106
this . value = o . value ;
107
+ this . query = query ;
99
108
}
100
109
101
110
get lenth ( ) {
@@ -381,7 +390,7 @@ export class AutoComplete {
381
390
this . ul . innerHTML = "" ;
382
391
383
392
this . suggestions = list
384
- . map ( item => new Suggestion ( this . data ( item , value ) ) )
393
+ . map ( item => new Suggestion ( this . data ( item , value ) , value ) )
385
394
. filter ( item => this . filter ( item , value ) ) ;
386
395
387
396
if ( this . sort !== false ) {
You can’t perform that action at this time.
0 commit comments