Skip to content

Commit adf1b7c

Browse files
authored
Merge pull request #28 from KazanExpress/dev
New Minor. Again.
2 parents b78c6a5 + a9ce81e commit adf1b7c

File tree

9 files changed

+280
-132
lines changed

9 files changed

+280
-132
lines changed

README.md

+62-14
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,9 @@ Then, in your Vue.js component/page:
6464
<vue-suggest
6565
v-model="chosen"
6666
:list="simpleSuggestionList"
67-
></vue-suggest>
67+
:filter-by-query="true">
68+
<!-- Filter by query to only show the filtered results -->
69+
</vue-suggest>
6870

6971
<br>
7072

@@ -115,6 +117,7 @@ npm run dev
115117
# build example & readme for static serving
116118
npm run docs
117119
```
120+
118121
-----
119122
## Default Controls
120123

@@ -188,7 +191,7 @@ JS object:
188191
<input class="optional-custom-input">
189192

190193
<!-- 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 }">
192195
<div class="misc-item">
193196
<span>You're searching for {{ query }}.</span>
194197
</div>
@@ -198,10 +201,10 @@ JS object:
198201
<hr>
199202
</template>
200203

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>
202205

203206
<!-- 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">
205208
<span>Loading...</span>
206209
</div>
207210
</vue-simple-suggest>
@@ -211,6 +214,7 @@ JS object:
211214
### API definitions
212215

213216
#### Props
217+
214218
| Name | Type | Default | Description |
215219
|--------------------------------|----------|----------|--------------------------------------------------------------|
216220
| `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:
225229
| `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). |
226230
| `type`, `value`, `pattern`, etc... | | | All of the HTML5 input attributes with their respected default values. |
227231

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+
228249
-----
229250
#### Emitted Events
230251
| Name | Arguments | Description |
@@ -262,7 +283,7 @@ JS object:
262283
#### Ref Event Handlers
263284
> accessed via `$refs.*your ref name here*`
264285
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.
266287

267288
| Name | Arguments | Description |
268289
|------|-----------|-------------|
@@ -288,8 +309,8 @@ You can use these to imitate come of the component's behaviours.
288309
|`inputElement`| `null` | Currently used HTMLInputElement. |
289310
|`canSend`| `true` | Whether the assigned getListFuncion can be executed. |
290311
|`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. |
293314
|`listIsRequest`| - | Whether the list prop is a function. |
294315
|`input`| - | A ref to the current input (component or vanilla). |
295316
|`hoveredIndex`| - | The current hovered element index. |
@@ -347,7 +368,7 @@ Defaults to a simple input with props passed to vue-simple-suggest.
347368
```
348369

349370
##### Custom suggestion item
350-
> `suggestionItem` slot
371+
> `suggestion-item` slot
351372
352373
Allows custom html-definitons of the suggestion items in a list.
353374
Defaults to `<span>{{ displayAttribute(suggestion) }}</span>`
@@ -357,7 +378,7 @@ Accepts the `suggestion` object and a `query` text as a `slot-scope` attribute v
357378
```html
358379
<!-- Example: -->
359380
<vue-simple-suggest>
360-
<div slot="suggestionItem" slot-scope="{ suggestion, query }">
381+
<div slot="suggestion-item" slot-scope="{ suggestion, query }">
361382
<div>My {{ suggestion.title }}</div>
362383
</div>
363384
</vue-simple-suggest>
@@ -368,7 +389,7 @@ In cooperation with [ref fields](#ref-methods) can be used to drastically transf
368389
One of the simplest examples - highlighting the query text in the results:
369390

370391
```html
371-
<div slot="suggestionItem" slot-scope="scope">
392+
<div slot="suggestion-item" slot-scope="scope">
372393
<span v-html="boldenSuggestion(scope)"></span>
373394
</div>
374395
```
@@ -394,10 +415,10 @@ boldenSuggestion({ suggestion, query }) {
394415
```
395416
Result:
396417

397-
![](/assets/screenshot.jpg)
418+
![](assets/screenshot.jpg)
398419

399420
##### Custom miscellanious item slots
400-
> `miscItem-above` and `miscItem-below` slots
421+
> `misc-item-above` and `misc-item-below` slots
401422
402423
Allow custom elements to be shown in suggestion list. These elements never dissapear from the list, niether can they be selected nor hovered on.
403424

@@ -410,7 +431,7 @@ Accept the `suggestions` array and a `query` text as a `slot-scope` attribute va
410431
```html
411432
<!-- Examples: -->
412433
<vue-simple-suggest>
413-
<template slot="miscItem-above" slot-scope="{ suggestions, query }">
434+
<template slot="misc-item-above" slot-scope="{ suggestions, query }">
414435
<div class="misc-item">
415436
<span>You're searching for {{ query }}.</span>
416437
</div>
@@ -419,8 +440,35 @@ Accept the `suggestions` array and a `query` text as a `slot-scope` attribute va
419440
</div>
420441
</template>
421442

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">
423444
<span>Loading...</span>
424445
</div>
425446
</vue-simple-suggest>
426447
```
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

Comments
 (0)