Skip to content

Commit b35013a

Browse files
committed
2 parents a100d4e + 01fd0df commit b35013a

File tree

10 files changed

+85
-38
lines changed

10 files changed

+85
-38
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,25 +82,25 @@ Then, in your Vue.js component/page:
8282
```html
8383
<!-- Some component.vue -->
8484
<template>
85-
<vue-suggest
85+
<vue-simple-suggest
8686
v-model="chosen"
8787
:list="simpleSuggestionList"
8888
:filter-by-query="true">
8989
<!-- Filter by input text to only show the matching results -->
90-
</vue-suggest>
90+
</vue-simple-suggest>
9191

9292
<br>
9393

9494
<p>Chosen element: {{ chosen }}</p>
9595
</template>
9696

9797
<script>
98-
import VueSuggest from 'vue-simple-suggest'
98+
import VueSimpleSuggest from 'vue-simple-suggest'
9999
import 'vue-simple-suggest/dist/styles.css' // Optional CSS
100100
101101
export default {
102102
components: {
103-
VueSuggest
103+
VueSimpleSuggest
104104
},
105105
data() {
106106
return {

dist/cjs.js

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,7 @@ function _finally(body, finalizer) {
9999
}if (result && result.then) {
100100
return result.then(void 0, recover);
101101
}return result;
102-
}
103-
function _invokeIgnored(body) {
102+
}function _invokeIgnored(body) {
104103
var result = body();if (result && result.then) {
105104
return result.then(_empty);
106105
}
@@ -237,7 +236,7 @@ var VueSimpleSuggest = {
237236
}
238237
}
239238
}),
240-
// Handle run-time mode changes:
239+
// Handle run-time mode changes (not working):
241240
watch: {
242241
mode: function mode(v) {
243242
return event = v;
@@ -303,14 +302,31 @@ var VueSimpleSuggest = {
303302

304303
methods: {
305304
isScopedSlotEmpty: function isScopedSlotEmpty(slot) {
306-
return slot && typeof slot === 'function' ? !slot(this) : !slot;
305+
if (slot) {
306+
var vNode = slot(this);
307+
return !(Array.isArray(vNode) || vNode && (vNode.tag || vNode.context || vNode.text || vNode.children));
308+
}
309+
310+
return true;
307311
},
308312
miscSlotsAreEmpty: function miscSlotsAreEmpty() {
309313
var _this2 = this;
310314

311-
return ['above', 'below'].some(function (slotName) {
312-
return _this2.isScopedSlotEmpty(_this2.$scopedSlots['misc-item-' + slotName]);
315+
var slots = ['misc-item-above', 'misc-item-below'].map(function (s) {
316+
return _this2.$scopedSlots[s];
317+
});
318+
319+
if (slots.every(function (s) {
320+
return !!s;
321+
})) {
322+
return slots.every(this.isScopedSlotEmpty.bind(this));
323+
}
324+
325+
var slot = slots.find(function (s) {
326+
return !!s;
313327
});
328+
329+
return this.isScopedSlotEmpty.call(this, slot);
314330
},
315331
displayProperty: function displayProperty(obj) {
316332
return (this.isPlainSuggestion ? obj : fromPath(obj, this.displayAttribute)) + '';
@@ -509,8 +525,7 @@ var VueSimpleSuggest = {
509525

510526
if (_this5.listShown && !value && _this5.minLength > 0) {
511527
_this5.hideList();
512-
_this5.clearSuggestions();
513-
return _this5.suggestions;
528+
return [];
514529
}
515530

516531
if (value.length < _this5.minLength) {
@@ -522,6 +537,10 @@ var VueSimpleSuggest = {
522537
// Start request if can
523538
if (_this5.listIsRequest) {
524539
_this5.$emit('request-start', value);
540+
541+
if (_this5.suggestions.length > 0 || !_this5.miscSlotsAreEmpty()) {
542+
_this5.showList();
543+
}
525544
}
526545

527546
var result = [];

dist/es6.js

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,7 @@ function _finally(body, finalizer) {
8383
}if (result && result.then) {
8484
return result.then(void 0, recover);
8585
}return result;
86-
}
87-
function _invokeIgnored(body) {
86+
}function _invokeIgnored(body) {
8887
var result = body();if (result && result.then) {
8988
return result.then(_empty);
9089
}
@@ -215,7 +214,7 @@ var VueSimpleSuggest = {
215214
validator: value => !!~Object.keys(modes).indexOf(value.toLowerCase())
216215
}
217216
}),
218-
// Handle run-time mode changes:
217+
// Handle run-time mode changes (not working):
219218
watch: {
220219
mode: v => event = v
221220
},
@@ -273,10 +272,23 @@ var VueSimpleSuggest = {
273272
},
274273
methods: {
275274
isScopedSlotEmpty(slot) {
276-
return slot && typeof slot === 'function' ? !slot(this) : !slot;
275+
if (slot) {
276+
const vNode = slot(this);
277+
return !(Array.isArray(vNode) || vNode && (vNode.tag || vNode.context || vNode.text || vNode.children));
278+
}
279+
280+
return true;
277281
},
278282
miscSlotsAreEmpty() {
279-
return ['above', 'below'].some(slotName => this.isScopedSlotEmpty(this.$scopedSlots['misc-item-' + slotName]));
283+
const slots = ['misc-item-above', 'misc-item-below'].map(s => this.$scopedSlots[s]);
284+
285+
if (slots.every(s => !!s)) {
286+
return slots.every(this.isScopedSlotEmpty.bind(this));
287+
}
288+
289+
const slot = slots.find(s => !!s);
290+
291+
return this.isScopedSlotEmpty.call(this, slot);
280292
},
281293
displayProperty(obj) {
282294
return (this.isPlainSuggestion ? obj : fromPath(obj, this.displayAttribute)) + '';
@@ -475,8 +487,7 @@ var VueSimpleSuggest = {
475487

476488
if (_this3.listShown && !value && _this3.minLength > 0) {
477489
_this3.hideList();
478-
_this3.clearSuggestions();
479-
return _this3.suggestions;
490+
return [];
480491
}
481492

482493
if (value.length < _this3.minLength) {
@@ -488,6 +499,10 @@ var VueSimpleSuggest = {
488499
// Start request if can
489500
if (_this3.listIsRequest) {
490501
_this3.$emit('request-start', value);
502+
503+
if (_this3.suggestions.length > 0 || !_this3.miscSlotsAreEmpty()) {
504+
_this3.showList();
505+
}
491506
}
492507

493508
let result = [];

dist/es7.js

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ var VueSimpleSuggest = {
158158
validator: value => !!~Object.keys(modes).indexOf(value.toLowerCase())
159159
}
160160
}),
161-
// Handle run-time mode changes:
161+
// Handle run-time mode changes (not working):
162162
watch: {
163163
mode: v => event = v
164164
},
@@ -216,10 +216,23 @@ var VueSimpleSuggest = {
216216
},
217217
methods: {
218218
isScopedSlotEmpty(slot) {
219-
return slot && typeof slot === 'function' ? !slot(this) : !slot;
219+
if (slot) {
220+
const vNode = slot(this);
221+
return !(Array.isArray(vNode) || vNode && (vNode.tag || vNode.context || vNode.text || vNode.children));
222+
}
223+
224+
return true;
220225
},
221226
miscSlotsAreEmpty() {
222-
return ['above', 'below'].some(slotName => this.isScopedSlotEmpty(this.$scopedSlots['misc-item-' + slotName]));
227+
const slots = ['misc-item-above', 'misc-item-below'].map(s => this.$scopedSlots[s]);
228+
229+
if (slots.every(s => !!s)) {
230+
return slots.every(this.isScopedSlotEmpty.bind(this));
231+
}
232+
233+
const slot = slots.find(s => !!s);
234+
235+
return this.isScopedSlotEmpty.call(this, slot);
223236
},
224237
displayProperty(obj) {
225238
return (this.isPlainSuggestion ? obj : fromPath(obj, this.displayAttribute)) + '';
@@ -402,8 +415,7 @@ var VueSimpleSuggest = {
402415
async getSuggestions(value = '') {
403416
if (this.listShown && !value && this.minLength > 0) {
404417
this.hideList();
405-
this.clearSuggestions();
406-
return this.suggestions;
418+
return [];
407419
}
408420

409421
if (value.length < this.minLength) {
@@ -415,6 +427,10 @@ var VueSimpleSuggest = {
415427
// Start request if can
416428
if (this.listIsRequest) {
417429
this.$emit('request-start', value);
430+
431+
if (this.suggestions.length > 0 || !this.miscSlotsAreEmpty()) {
432+
this.showList();
433+
}
418434
}
419435

420436
let result = [];

dist/iife.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.

dist/umd.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.

docs/index.html

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -182,25 +182,22 @@
182182
<span class=hljs-tag>&lt;/<span class=hljs-name>div</span>&gt;</span>
183183
<span class=hljs-tag>&lt;/<span class=hljs-name>vue-simple-suggest</span>&gt;</span></code></pre><p>These slots can also be used to handle empty results, like this:</p> <pre class=hljs><code><span class=hljs-comment>&lt;!-- Main slot template --&gt;</span>
184184
<span class=hljs-tag>&lt;<span class=hljs-name>template</span> <span class=hljs-attr>slot</span>=<span class=hljs-string>"misc-item-above"</span> <span class=hljs-attr>slot-scope</span>=<span class=hljs-string>"{ suggestions, query }"</span>&gt;</span>
185+
<span class=hljs-tag>&lt;<span class=hljs-name>div</span> <span class=hljs-attr>class</span>=<span class=hljs-string>"misc-item"</span>&gt;</span>
186+
<span class=hljs-tag>&lt;<span class=hljs-name>span</span>&gt;</span>You're searching for '{{ query }}'.<span class=hljs-tag>&lt;/<span class=hljs-name>span</span>&gt;</span>
187+
<span class=hljs-tag>&lt;/<span class=hljs-name>div</span>&gt;</span>
185188

186189
<span class=hljs-comment>&lt;!-- Sub-template if have any suggestions --&gt;</span>
187190
<span class=hljs-tag>&lt;<span class=hljs-name>template</span> <span class=hljs-attr>v-if</span>=<span class=hljs-string>"suggestions.length &gt; 0"</span>&gt;</span>
188-
<span class=hljs-tag>&lt;<span class=hljs-name>div</span> <span class=hljs-attr>class</span>=<span class=hljs-string>"misc-item"</span>&gt;</span>
189-
<span class=hljs-tag>&lt;<span class=hljs-name>span</span>&gt;</span>You're searching for '{{ query }}'.<span class=hljs-tag>&lt;/<span class=hljs-name>span</span>&gt;</span>
190-
<span class=hljs-tag>&lt;/<span class=hljs-name>div</span>&gt;</span>
191191
<span class=hljs-tag>&lt;<span class=hljs-name>div</span> <span class=hljs-attr>class</span>=<span class=hljs-string>"misc-item"</span>&gt;</span>
192192
<span class=hljs-tag>&lt;<span class=hljs-name>span</span>&gt;</span>{{ suggestions.length }} suggestions are shown...<span class=hljs-tag>&lt;/<span class=hljs-name>span</span>&gt;</span>
193193
<span class=hljs-tag>&lt;/<span class=hljs-name>div</span>&gt;</span>
194194
<span class=hljs-tag>&lt;<span class=hljs-name>hr</span>&gt;</span>
195195
<span class=hljs-tag>&lt;/<span class=hljs-name>template</span>&gt;</span>
196196

197197
<span class=hljs-comment>&lt;!-- Show "No result" otherwise, if not loading new ones --&gt;</span>
198-
<span class=hljs-tag>&lt;<span class=hljs-name>template</span> <span class=hljs-attr>v-else-if</span>=<span class=hljs-string>"!loading"</span>&gt;</span>
199-
<span class=hljs-tag>&lt;<span class=hljs-name>div</span> <span class=hljs-attr>class</span>=<span class=hljs-string>"misc-item"</span>&gt;</span>
200-
<span class=hljs-tag>&lt;<span class=hljs-name>span</span>&gt;</span>No results<span class=hljs-tag>&lt;/<span class=hljs-name>span</span>&gt;</span>
201-
<span class=hljs-tag>&lt;/<span class=hljs-name>div</span>&gt;</span>
202-
<span class=hljs-tag>&lt;/<span class=hljs-name>template</span>&gt;</span>
203-
198+
<span class=hljs-tag>&lt;<span class=hljs-name>div</span> <span class=hljs-attr>class</span>=<span class=hljs-string>"misc-item"</span> <span class=hljs-attr>v-else-if</span>=<span class=hljs-string>"!loading"</span>&gt;</span>
199+
<span class=hljs-tag>&lt;<span class=hljs-name>span</span>&gt;</span>No results<span class=hljs-tag>&lt;/<span class=hljs-name>span</span>&gt;</span>
200+
<span class=hljs-tag>&lt;/<span class=hljs-name>div</span>&gt;</span>
204201
<span class=hljs-tag>&lt;/<span class=hljs-name>template</span>&gt;</span></code></pre> </article> <script type="text/javascript" src="main.js"></script></body> </html>
205202
</body>
206203
</html>

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.

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.6.2",
4+
"version": "1.6.3",
55
"author": "KazanExpress",
66
"license": "MIT",
77
"repository": "KazanExpress/vue-simple-suggest",

0 commit comments

Comments
 (0)