Skip to content

Commit f7b94f4

Browse files
author
Damian Dulisz
committed
2.0-beta.9
1 parent f3a1c4c commit f7b94f4

File tree

8 files changed

+76
-20
lines changed

8 files changed

+76
-20
lines changed

README.md

+17-2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,13 @@ Probably the most complete *selecting* solution for Vue.js 2.0, without jQuery.
1717
* \> 99% test coverage
1818
* Fully configurable (see props list below)
1919

20+
## Breaking changes:
21+
* Instead of Vue.partial for custom option templates you can use a custom render function.
22+
* The `:key` props has changed to `:track-by`, due to conflicts with Vue 2.0.
23+
* Support for `v-model`
24+
* `@update` has changed to `@input` to also work with v-model
25+
* `:selected` has changed to `:value` for the same reason
26+
2027
## Install & basic usage
2128

2229
``` bash
@@ -65,8 +72,6 @@ export default {
6572
## Roadmap:
6673

6774
* Grouping
68-
* Support for partials
69-
* Examples of custom components / templates ready to use in project
7075

7176
## Examples
7277
in jade-lang/pug-lang
@@ -330,6 +335,16 @@ props: {
330335
*/
331336
id: {
332337
default: null
338+
},
339+
/**
340+
* Limits the options displayed in the dropdown
341+
* to the first X options.
342+
* @default 1000
343+
* @type {Integer}
344+
*/
345+
optionsLimit: {
346+
type: Number,
347+
default: 1000
333348
}
334349
}
335350

docs/main.js

+8-12
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ require('./docs.scss')
55
import countries from './data/countries.json'
66
import Multiselect from '../src/Multiselect'
77

8+
let moreCountries = []
9+
for (var i = 0; i < 100; i++) {
10+
moreCountries = moreCountries.concat(countries)
11+
}
12+
console.log(moreCountries.length)
13+
814
function throttle (callback, limit) {
915
var wait = false
1016
return function () {
@@ -47,7 +53,7 @@ new Vue({
4753
taggingSelected: [],
4854
searchable: true,
4955
placeholder: 'Select props',
50-
countries: [],
56+
countries: moreCountries,
5157
selectedCountries: [],
5258
actions: ['alert', 'console.log', 'scrollTop'],
5359
action: null,
@@ -71,17 +77,7 @@ new Vue({
7177
},
7278
methods: {
7379
asyncFind (query) {
74-
if (query.length === 0) {
75-
this.countries = []
76-
} else {
77-
this.isLoading = true
78-
setTimeout(() => {
79-
this.countries = countries.filter((element, index, array) => {
80-
return element.name.toLowerCase().includes(query.toLowerCase())
81-
})
82-
this.isLoading = false
83-
}, 1000)
84-
}
80+
this.countries = moreCountries.filter(country => country.name.toLowerCase().includes(query.toLowerCase()))
8581
},
8682
onTagging (newTag) {
8783
this.source.push({ name: newTag, language: newTag })

docs/partials/examples/_ajax-search.jade

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,14 @@ p.typo__p
88
.grid__column.grid__unit--md-5
99
label.typo__label Async multiselect
1010
multiselect(
11+
v-model="selectedCountries",
1112
:options="countries",
12-
:value="selectedCountries",
1313
:multiple="multiple",
1414
:searchable="searchable",
1515
:clear-on-select="false",
1616
:close-on-select="false",
1717
:loading="isLoading",
18+
:options-limit="300",
1819
id="ajax",
1920
@search-change="asyncFind",
2021
label="name"
@@ -40,7 +41,6 @@ p.typo__p
4041
:close-on-select="false",
4142
:loading="isLoading",
4243
id="ajax",
43-
@search-change="asyncFind",
4444
label="name"
4545
track-by="code"
4646
placeholder="Type to search"

lib/multiselectMixin.js

+11-1
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,16 @@ module.exports = {
187187
*/
188188
id: {
189189
default: null
190+
},
191+
/**
192+
* Limits the options displayed in the dropdown
193+
* to the first X options.
194+
* @default 1000
195+
* @type {Integer}
196+
*/
197+
optionsLimit: {
198+
type: Number,
199+
default: 1000
190200
}
191201
},
192202
created () {
@@ -206,7 +216,7 @@ module.exports = {
206216
if (this.taggable && search.length && !this.isExistingOption(search)) {
207217
options.unshift({ isTag: true, label: search })
208218
}
209-
return options
219+
return options.slice(0, this.optionsLimit)
210220
},
211221
valueKeys () {
212222
if (this.trackBy) {

lib/vue-multiselect.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "vue-multiselect",
3-
"version": "2.0.0-beta.8",
3+
"version": "2.0.0-beta.9",
44
"description": "Multiselect component for vue.js",
55
"author": "Damian Dulisz <[email protected]>",
66
"private": false,

src/multiselectMixin.js

+11-1
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,16 @@ module.exports = {
187187
*/
188188
id: {
189189
default: null
190+
},
191+
/**
192+
* Limits the options displayed in the dropdown
193+
* to the first X options.
194+
* @default 1000
195+
* @type {Integer}
196+
*/
197+
optionsLimit: {
198+
type: Number,
199+
default: 1000
190200
}
191201
},
192202
created () {
@@ -206,7 +216,7 @@ module.exports = {
206216
if (this.taggable && search.length && !this.isExistingOption(search)) {
207217
options.unshift({ isTag: true, label: search })
208218
}
209-
return options
219+
return options.slice(0, this.optionsLimit)
210220
},
211221
valueKeys () {
212222
if (this.trackBy) {

test/unit/specs/Multiselect.spec.js

+25
Original file line numberDiff line numberDiff line change
@@ -1983,6 +1983,31 @@ describe('Multiselect.vue', () => {
19831983
expect(comp.filteredOptions).to.deep.equal([10, 20, 30])
19841984
expect(comp.filteredOptions.length).to.equal(3)
19851985
})
1986+
1987+
it('should return only as many options as set in the :options-limit prop.', () => {
1988+
const vm = new Vue({
1989+
render (h) {
1990+
return h(Multiselect, {
1991+
props: {
1992+
value: this.value,
1993+
options: this.source,
1994+
multiple: true,
1995+
optionsLimit: 2
1996+
}
1997+
})
1998+
},
1999+
components: { Multiselect },
2000+
data: {
2001+
value: [],
2002+
source: ['test', 'production', 'testing']
2003+
}
2004+
}).$mount()
2005+
expect(vm.$children[0].filteredOptions).to.deep.equal(['test', 'production'])
2006+
expect(vm.$children[0].filteredOptions.length).to.equal(2)
2007+
vm.$children[0].search = 'test'
2008+
expect(vm.$children[0].filteredOptions).to.deep.equal(['test', 'testing'])
2009+
expect(vm.$children[0].filteredOptions.length).to.equal(2)
2010+
})
19862011
})
19872012

19882013
describe('#onTag', () => {

0 commit comments

Comments
 (0)