Skip to content

Commit 18d6489

Browse files
authored
Merge pull request #24 from KazanExpress/dev
v1.4.0
2 parents fa3ed8d + 2388e15 commit 18d6489

File tree

9 files changed

+63
-33
lines changed

9 files changed

+63
-33
lines changed

README.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ npm install --save vue-simple-suggest
1717
- [What is it?](#what-is-it)
1818
- [Simple example](#simple-example)
1919
- [Build](#build-setup)
20-
- [Controls](#default-controls)
20+
- [Controls <sup>[v1.2.0](https://github.com/KazanExpress/vue-simple-suggest/releases/tag/v1.2.0)</sup>](#default-controls)
2121
- [Component API](#component-api)
2222
- [TLDR](#tldr)
2323
- [API Definitions](#api-definitions)
@@ -118,6 +118,8 @@ npm run docs
118118
-----
119119
## Default Controls
120120

121+
> New in [v1.2.0](https://github.com/KazanExpress/vue-simple-suggest/releases/tag/v1.2.0)
122+
121123
These are default keyboard shortcuts.
122124

123125
Can be customized with the [`controls` prop](#props). All fields in this `controls` object are optional.
@@ -154,6 +156,7 @@ JS object:
154156
<vue-simple-suggest ref="vueSimpleSuggest" v-model="model"
155157
value-attribute="id"
156158
display-attribute="title"
159+
mode="input"
157160
:placeholder="placeholder!!!"
158161
:list="getListFunction"
159162
:max-count="10"
@@ -210,7 +213,7 @@ JS object:
210213
#### Props
211214
| Name | Type | Default | Description |
212215
|--------------------------------|----------|----------|--------------------------------------------------------------|
213-
| `controls` | 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. |
216+
| `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. |
214217
| `max-suggestions` | Number | `10` | The maximum amount of suggestions to display. Set to 0 for infinite suggestions. |
215218
| `display-attribute` | String | `'title'` | The property in a suggestion object to display in a list. Supports dotted paths. |
216219
| `value-attribute` | String | `'id'` | The property in a suggestion object to use as a unique key. Supports dotted paths. |
@@ -219,7 +222,8 @@ JS object:
219222
| `destyled` | Boolean | `false` | Whether to cancel the default styling of input and suggestions list. |
220223
| `remove-list` | Boolean | `false` | If true - the suggestion list will be always hidden. |
221224
| `filter-by-query` | Boolean | `false` | Whether to filter the resulting suggestions by input's text query (make it a search component). |
222-
| type, value, pattern, etc... | | | All of the HTML5 input attributes with their respected default values. |
225+
| `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+
| `type`, `value`, `pattern`, etc... | | | All of the HTML5 input attributes with their respected default values. |
223227

224228
-----
225229
#### Emitted Events

docs/index.html

Lines changed: 4 additions & 3 deletions
Large diffs are not rendered by default.

docs/main.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

example/src/App.vue

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<template>
22
<div id="app">
33
<div class="example">
4-
<p>v-model: {{ model || 'empty' }}</p>
4+
<p>v-model: <span v-html="model || 'empty'"></span></p>
55
<vue-suggest class="asdad"
66
v-model="model"
77
:list="getList"
@@ -15,6 +15,7 @@
1515
select: [13, 36],
1616
hideList: [27, 35]
1717
}"
18+
:mode="mode"
1819
ref="suggestComponent"
1920
placeholder="Search books..."
2021
value-attribute="id"
@@ -80,6 +81,7 @@
8081
return {
8182
selected: null,
8283
model: '',
84+
mode: 'input',
8385
loading: false,
8486
log: []
8587
}

example/src/README.html

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
<li><a href="#what-is-it">What is it?</a></li>
2323
<li><a href="#simple-example">Simple example</a></li>
2424
<li><a href="#build-setup">Build</a></li>
25-
<li><a href="#default-controls">Controls</a></li>
25+
<li><a href="#default-controls">Controls <sup><a href="https://github.com/KazanExpress/vue-simple-suggest/releases/tag/v1.2.0">v1.2.0</a></sup></a></li>
2626
<li><a href="#component-api">Component API</a><ul class="list">
2727
<li><a href="#tldr">TLDR</a></li>
2828
<li><a href="#api-definitions">API Definitions</a><ul class="list">
@@ -108,6 +108,9 @@ <h2 id="build-setup"><a class="header-link" href="#build-setup"></a>Build Setup<
108108
<span class="hljs-comment"># build example &amp; readme for static serving</span>
109109
npm run docs</code></pre><hr>
110110
<h2 id="default-controls"><a class="header-link" href="#default-controls"></a>Default Controls</h2>
111+
<blockquote>
112+
<p>New in <a href="https://github.com/KazanExpress/vue-simple-suggest/releases/tag/v1.2.0">v1.2.0</a></p>
113+
</blockquote>
111114
<p>These are default keyboard shortcuts.</p>
112115
<p>Can be customized with the <a href="#props"><code>controls</code> prop</a>. All fields in this <code>controls</code> object are optional.</p>
113116
<p>Default scheme:</p>
@@ -159,6 +162,7 @@ <h3 id="tldr"><a class="header-link" href="#tldr"></a>TLDR</h3>
159162
<span class="hljs-tag">&lt;<span class="hljs-name">vue-simple-suggest</span> <span class="hljs-attr">ref</span>=<span class="hljs-string">"vueSimpleSuggest"</span> <span class="hljs-attr">v-model</span>=<span class="hljs-string">"model"</span>
160163
<span class="hljs-attr">value-attribute</span>=<span class="hljs-string">"id"</span>
161164
<span class="hljs-attr">display-attribute</span>=<span class="hljs-string">"title"</span>
165+
<span class="hljs-attr">mode</span>=<span class="hljs-string">"input"</span>
162166
<span class="hljs-attr">:placeholder</span>=<span class="hljs-string">"placeholder!!!"</span>
163167
<span class="hljs-attr">:list</span>=<span class="hljs-string">"getListFunction"</span>
164168
<span class="hljs-attr">:max-count</span>=<span class="hljs-string">"10"</span>
@@ -220,7 +224,7 @@ <h4 id="props"><a class="header-link" href="#props"></a>Props</h4>
220224
</thead>
221225
<tbody>
222226
<tr>
223-
<td><code>controls</code></td>
227+
<td><code>controls</code> <sup><a href="https://github.com/KazanExpress/vue-simple-suggest/releases/tag/v1.2.0">v1.2.0</a></sup></td>
224228
<td>Object</td>
225229
<td>See <a href="#default-controls">default controls</a></td>
226230
<td>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: <code>selectionUp</code>, <code>selectionDown</code>, <code>select</code>, <code>hideList</code> and <code>autocomplete</code>, all of which are optional.</td>
@@ -274,7 +278,13 @@ <h4 id="props"><a class="header-link" href="#props"></a>Props</h4>
274278
<td>Whether to filter the resulting suggestions by input&#39;s text query (make it a search component).</td>
275279
</tr>
276280
<tr>
277-
<td>type, value, pattern, etc...</td>
281+
<td><code>mode</code> <sup><a href="https://github.com/KazanExpress/vue-simple-suggest/releases/tag/v1.4.0">v1.4.0</a></sup></td>
282+
<td>String</td>
283+
<td><code>&#39;input&#39;</code></td>
284+
<td>The <code>v-model</code> event. Determines the event, that triggers <code>v-model</code>. Can be one of <code>&#39;input&#39;</code> (<code>v-model</code> binds a displayed property) or <code>&#39;select&#39;</code> (<code>v-model</code> binds a selected item).</td>
285+
</tr>
286+
<tr>
287+
<td><code>type</code>, <code>value</code>, <code>pattern</code>, etc...</td>
278288
<td></td>
279289
<td></td>
280290
<td>All of the HTML5 input attributes with their respected default values.</td>

lib/misc.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ export const defaultControls = {
66
autocomplete: [32, 13]
77
}
88

9+
export const modes = {
10+
input: String,
11+
select: Object,
12+
};
13+
914
export function fromPath(obj, path) {
1015
return path.split('.').reduce((o, i) => (o === Object(o) ? o[i] : o), obj);
1116
}

lib/vue-simple-suggest.vue

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
@keyup="onListKeyUp($event), onAutocomplete($event)"
88
ref="inputSlot">
99
<slot>
10-
<input v-bind="$props">
10+
<input v-bind="$props" :value="mode === 'input' ? value : text">
1111
</slot>
1212
</div>
1313
<div class="suggestions" v-if="!!listShown && !removeList" :class="{ designed: !destyled }">
@@ -42,12 +42,21 @@
4242
<script>
4343
import {
4444
defaultControls,
45+
modes,
4546
fromPath,
4647
hasKeyCode
4748
} from './misc'
4849
50+
let event = 'input'
51+
4952
export default {
5053
name: 'vue-simple-suggest',
54+
model: {
55+
prop: 'value',
56+
get event() {
57+
return event;
58+
}
59+
},
5160
props: {
5261
placeholder: {
5362
type: String
@@ -105,9 +114,18 @@ export default {
105114
default: 0
106115
},
107116
value: {
108-
type: String
117+
type: Object.values(modes),
118+
validator: (value) => value.constructor.name === modes[event].name
119+
},
120+
mode: {
121+
type: String,
122+
default: event,
123+
validator: (value) => !!~Object.keys(modes).indexOf(value.toLowerCase())
109124
}
110125
},
126+
// Handle run-time mode changes:
127+
watch: { mode: v => event = v },
128+
//
111129
data () {
112130
return {
113131
selected: null,
@@ -118,7 +136,11 @@ export default {
118136
canSend: true,
119137
timeoutInstance: null,
120138
text: this.value,
139+
140+
// TODO: Document this!
121141
isPlainSuggestion: false,
142+
//
143+
122144
controlScheme: {}
123145
}
124146
},
@@ -144,6 +166,7 @@ export default {
144166
},
145167
created() {
146168
this.controlScheme = Object.assign({}, defaultControls, this.controls);
169+
event = this.mode;
147170
},
148171
mounted () {
149172
this.inputElement = this.$refs['inputSlot'].querySelector('input')
@@ -169,10 +192,10 @@ export default {
169192
170193
// Ya know, input stuff
171194
this.$emit('input', this.displayProperty(item))
172-
this.inputElement.value = this.displayProperty(item);
173-
this.text = this.displayProperty(item);
195+
this.inputElement.value = this.displayProperty(item)
196+
this.text = this.displayProperty(item)
174197
175-
this.inputElement.focus();
198+
this.inputElement.focus()
176199
//
177200
178201
this.hovered = null
@@ -191,18 +214,12 @@ export default {
191214
}
192215
this.listShown = false
193216
this.$emit('hide-list')
194-
195-
// TODO: Deprecated, remove in the next minor update
196-
this.$emit('hideList')
197217
}
198218
},
199219
showList () {
200220
if (!this.listShown) {
201221
this.listShown = true
202222
this.$emit('show-list')
203-
204-
// TODO: Deprecated, remove in the next minor update
205-
this.$emit('showList')
206223
}
207224
},
208225
async onInputClick (event) {
@@ -323,9 +340,6 @@ export default {
323340
// Start request if can
324341
if (this.listIsRequest) {
325342
this.$emit('request-start', value)
326-
327-
// TODO: Deprecated, remove in the next minor update
328-
this.$emit('requestStart', value)
329343
}
330344
331345
let result = [];
@@ -347,18 +361,12 @@ export default {
347361
348362
if (this.listIsRequest) {
349363
this.$emit('request-done', result)
350-
351-
// TODO: Deprecated, remove in the next minor update
352-
this.$emit('requestDone', result)
353364
}
354365
}
355366
356367
catch (e) {
357368
if (this.listIsRequest) {
358369
this.$emit('request-failed', e)
359-
360-
// TODO: Deprecated, remove in the next minor update
361-
this.$emit('requestFailed', e)
362370
} else {
363371
throw e;
364372
}

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "vue-simple-suggest",
33
"description": "Feature-rich autocomplete component for Vue.js",
4-
"version": "1.3.0",
4+
"version": "1.4.0",
55
"author": "KazanExpress",
66
"license": "MIT",
77
"repository": "KazanExpress/vue-simple-suggest",

0 commit comments

Comments
 (0)