@@ -64,7 +64,9 @@ Then, in your Vue.js component/page:
64
64
<vue-suggest
65
65
v-model =" chosen"
66
66
:list =" simpleSuggestionList"
67
- ></vue-suggest >
67
+ :filter-by-query =" true" >
68
+ <!-- Filter by query to only show the filtered results -->
69
+ </vue-suggest >
68
70
69
71
<br >
70
72
@@ -115,6 +117,7 @@ npm run dev
115
117
# build example & readme for static serving
116
118
npm run docs
117
119
```
120
+
118
121
-----
119
122
## Default Controls
120
123
@@ -188,7 +191,7 @@ JS object:
188
191
<input class =" optional-custom-input" >
189
192
190
193
<!-- Appears o top of the list -->
191
- <template slot =" miscItem -above" slot-scope =" { suggestions, query }" >
194
+ <template slot =" misc-item -above" slot-scope =" { suggestions, query }" >
192
195
<div class =" misc-item" >
193
196
<span >You're searching for {{ query }}.</span >
194
197
</div >
@@ -198,10 +201,10 @@ JS object:
198
201
<hr >
199
202
</template >
200
203
201
- <div slot =" suggestionItem " slot-scope =" { suggestion }" class =" custom" >{{ suggestion.title }}</div >
204
+ <div slot =" suggestion-item " slot-scope =" { suggestion }" class =" custom" >{{ suggestion.title }}</div >
202
205
203
206
<!-- Appears below the list -->
204
- <div class =" misc-item" slot =" miscItem -below" slot-scope =" { suggestions }" v-if =" loading" >
207
+ <div class =" misc-item" slot =" misc-item -below" slot-scope =" { suggestions }" v-if =" loading" >
205
208
<span >Loading...</span >
206
209
</div >
207
210
</vue-simple-suggest >
@@ -211,6 +214,7 @@ JS object:
211
214
### API definitions
212
215
213
216
#### Props
217
+
214
218
| Name | Type | Default | Description |
215
219
| --------------------------------| ----------| ----------| --------------------------------------------------------------|
216
220
| ` controls ` <sup >[ v1.2.0] ( https://github.com/KazanExpress/vue-simple-suggest/releases/tag/v1.2.0 ) </sup > | Object | See [ default controls] ( #default-controls ) | Determines the keyboard shortcuts in key-codes (for browser-compatibility purposes). Arrays provide the ability to assign multiple keys to one action. Consists of 5 array fields: ` selectionUp ` , ` selectionDown ` , ` select ` , ` hideList ` and ` autocomplete ` , all of which are optional. |
@@ -225,6 +229,23 @@ JS object:
225
229
| ` mode ` <sup >[ v1.4.0] ( https://github.com/KazanExpress/vue-simple-suggest/releases/tag/v1.4.0 ) </sup > | String | ` 'input' ` | The ` v-model ` event. Determines the event, that triggers ` v-model ` . Can be one of ` 'input' ` (` v-model ` binds a displayed property) or ` 'select' ` (` v-model ` binds a selected item). |
226
230
| ` type ` , ` value ` , ` pattern ` , etc... | | | All of the HTML5 input attributes with their respected default values. |
227
231
232
+ ##### mode
233
+ > New in [ v1.4.0] ( https://github.com/KazanExpress/vue-simple-suggest/releases/tag/v1.4.0 )
234
+
235
+ Determines the event, that triggers ` v-model ` . Can be one of ` 'input' ` (default) or ` 'select' ` .
236
+
237
+ For example, if ` 'input' ` is chosen - then v-model will update the value each time an [ ` input ` ] ( #emitted-events ) event is fired, setting the input's string.
238
+
239
+ Same is for ` 'select' ` - v-model changes only when something is selected from the list, setting the selected value (string, object or whatever) to its argument.
240
+
241
+ A proper use-case for it being when one wants to use the component only for selection binding and custom input for text binding:
242
+
243
+ ``` html
244
+ <vue-simple-suggest v-model =" selected" mode =" select" >
245
+ <input v-model =" text" >
246
+ </vue-simple-suggest >
247
+ ```
248
+
228
249
-----
229
250
#### Emitted Events
230
251
| Name | Arguments | Description |
@@ -262,7 +283,7 @@ JS object:
262
283
#### Ref Event Handlers
263
284
> accessed via ` $refs.*your ref name here* `
264
285
265
- You can use these to imitate come of the component's behaviours.
286
+ You can use these to imitate some of the component's behaviours.
266
287
267
288
| Name | Arguments | Description |
268
289
| ------| -----------| -------------|
@@ -288,8 +309,8 @@ You can use these to imitate come of the component's behaviours.
288
309
| ` inputElement ` | ` null ` | Currently used HTMLInputElement. |
289
310
| ` canSend ` | ` true ` | Whether the assigned getListFuncion can be executed. |
290
311
| ` timeoutInstance ` | ` null ` | The timeout until next getListFunction execution. |
291
- | ` text ` | ` vueSimpleSuggest. $props.value` | Current input text. |
292
- | ` slotIsComponent ` | - | Whether this current custom input is a vue-component. |
312
+ | ` text ` | ` $props.value ` | Current input text. |
313
+ | ` slotIsComponent ` | ` false ` | Whether this current custom input is a vue-component. |
293
314
| ` listIsRequest ` | - | Whether the list prop is a function. |
294
315
| ` input ` | - | A ref to the current input (component or vanilla). |
295
316
| ` hoveredIndex ` | - | The current hovered element index. |
@@ -347,7 +368,7 @@ Defaults to a simple input with props passed to vue-simple-suggest.
347
368
```
348
369
349
370
##### Custom suggestion item
350
- > ` suggestionItem ` slot
371
+ > ` suggestion-item ` slot
351
372
352
373
Allows custom html-definitons of the suggestion items in a list.
353
374
Defaults to ` <span>{{ displayAttribute(suggestion) }}</span> `
@@ -357,7 +378,7 @@ Accepts the `suggestion` object and a `query` text as a `slot-scope` attribute v
357
378
``` html
358
379
<!-- Example: -->
359
380
<vue-simple-suggest >
360
- <div slot =" suggestionItem " slot-scope =" { suggestion, query }" >
381
+ <div slot =" suggestion-item " slot-scope =" { suggestion, query }" >
361
382
<div >My {{ suggestion.title }}</div >
362
383
</div >
363
384
</vue-simple-suggest >
@@ -368,7 +389,7 @@ In cooperation with [ref fields](#ref-methods) can be used to drastically transf
368
389
One of the simplest examples - highlighting the query text in the results:
369
390
370
391
``` html
371
- <div slot =" suggestionItem " slot-scope =" scope" >
392
+ <div slot =" suggestion-item " slot-scope =" scope" >
372
393
<span v-html =" boldenSuggestion(scope)" ></span >
373
394
</div >
374
395
```
@@ -394,10 +415,10 @@ boldenSuggestion({ suggestion, query }) {
394
415
```
395
416
Result:
396
417
397
- ![ ] ( / assets/screenshot.jpg)
418
+ ![ ] ( assets/screenshot.jpg )
398
419
399
420
##### Custom miscellanious item slots
400
- > ` miscItem- above` and ` miscItem -below` slots
421
+ > ` misc-item- above` and ` misc-item -below` slots
401
422
402
423
Allow custom elements to be shown in suggestion list. These elements never dissapear from the list, niether can they be selected nor hovered on.
403
424
@@ -410,7 +431,7 @@ Accept the `suggestions` array and a `query` text as a `slot-scope` attribute va
410
431
``` html
411
432
<!-- Examples: -->
412
433
<vue-simple-suggest >
413
- <template slot =" miscItem -above" slot-scope =" { suggestions, query }" >
434
+ <template slot =" misc-item -above" slot-scope =" { suggestions, query }" >
414
435
<div class =" misc-item" >
415
436
<span >You're searching for {{ query }}.</span >
416
437
</div >
@@ -419,8 +440,35 @@ Accept the `suggestions` array and a `query` text as a `slot-scope` attribute va
419
440
</div >
420
441
</template >
421
442
422
- <div slot =" miscItem -below" slot-scope =" { suggestions }" v-if =" isLoading" class =" misc-item" >
443
+ <div slot =" misc-item -below" slot-scope =" { suggestions }" v-if =" isLoading" class =" misc-item" >
423
444
<span >Loading...</span >
424
445
</div >
425
446
</vue-simple-suggest >
426
447
```
448
+
449
+ These slots can also be used to handle empty results, like this:
450
+
451
+ ``` html
452
+ <!-- Main slot template -->
453
+ <template slot =" misc-item-above" slot-scope =" { suggestions, query }" >
454
+
455
+ <!-- Sub-template if have any suggestions -->
456
+ <template v-if =" suggestions.length > 0" >
457
+ <div class =" misc-item" >
458
+ <span >You're searching for '{{ query }}'.</span >
459
+ </div >
460
+ <div class =" misc-item" >
461
+ <span >{{ suggestions.length }} suggestions are shown...</span >
462
+ </div >
463
+ <hr >
464
+ </template >
465
+
466
+ <!-- Show "No result" otherwise, if not loading new ones -->
467
+ <template v-else-if =" !loading" >
468
+ <div class =" misc-item" >
469
+ <span >No results</span >
470
+ </div >
471
+ </template >
472
+
473
+ </template >
474
+ ```
0 commit comments