Skip to content

Commit a932fb2

Browse files
author
Damian Dulisz
committed
Fix shentao#94. Introduce optionsLimit
1 parent 894aa01 commit a932fb2

File tree

5 files changed

+48
-3
lines changed

5 files changed

+48
-3
lines changed

README.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Probably the most complete *selecting* solution for Vue.js, without jQuery.
44
#### Current version: v1.1.2
55

66
#### For Vue 2.0 users:
7-
Vue-multiselect 2.0-beta is available: `npm install vue-multiselect@next`.
7+
Vue-multiselect 2.0-beta is available: `npm install vue-multiselect@next`.
88
API changes:
99
* Instead of Vue.partial for custom option templates you can use a custom render function.
1010
* The `:key` props has changed to `:track-by`, due to conflicts with Vue 2.0.
@@ -393,6 +393,16 @@ props: {
393393
*/
394394
id: {
395395
default: null
396+
},
397+
/**
398+
* Limits the options displayed in the dropdown
399+
* to the first X options.
400+
* @default 1000
401+
* @type {Integer}
402+
*/
403+
optionsLimit: {
404+
type: Number,
405+
default: 1000
396406
}
397407
}
398408

docs/partials/api/_props.jade

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,15 @@ h2.typo__h2#props Props
137137
td.table__td
138138
td.table__td
139139
| Number of allowed selected options.
140+
tr.table__tr
141+
td.table__td
142+
strong OptionsLimit
143+
br
144+
kbd v1.2+
145+
td.table__td Number
146+
td.table__td: kbd 1000
147+
td.table__td
148+
| Limit the elements in the dropdown to the first X options that match the search query. Useful for optimization.
140149

141150
tr.table__tr
142151
td.table__td.utils--center(colspan="4"): strong Multiselect.vue

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@
8888
"sinon": "^1.17.3",
8989
"sinon-chai": "^2.8.0",
9090
"url-loader": "^0.5.7",
91-
"vue": "^1.0.21",
91+
"vue": "^1.0.26",
9292
"vue-hot-reload-api": "^1.2.0",
9393
"vue-html-loader": "^1.0.0",
9494
"vue-loader": "^8.2.1",

src/multiselectMixin.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,16 @@ module.exports = {
178178
*/
179179
id: {
180180
default: null
181+
},
182+
/**
183+
* Limits the options displayed in the dropdown
184+
* to the first X options.
185+
* @default 1000
186+
* @type {Integer}
187+
*/
188+
optionsLimit: {
189+
type: Number,
190+
default: 1000
181191
}
182192
},
183193
created () {
@@ -193,7 +203,7 @@ module.exports = {
193203
if (this.taggable && search.length && !this.isExistingOption(search)) {
194204
options.unshift({ isTag: true, label: search })
195205
}
196-
return options
206+
return options.slice(0, this.optionsLimit)
197207
},
198208
valueKeys () {
199209
if (this.key) {

test/unit/specs/Multiselect.spec.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1228,6 +1228,22 @@ describe('Multiselect.vue', () => {
12281228
expect(vm.$children[0].filteredOptions).to.deep.equal([10, 20, 30])
12291229
expect(vm.$children[0].filteredOptions.length).to.equal(3)
12301230
})
1231+
1232+
it('should return only as many options as set in the :options-limit prop.', () => {
1233+
const vm = new Vue({
1234+
template: '<multiselect :selected="value" :options="source" :multiple="true" :options-limit="2"></multiselect>',
1235+
components: { Multiselect },
1236+
data: {
1237+
value: [],
1238+
source: ['test', 'production', 'testing']
1239+
}
1240+
}).$mount()
1241+
expect(vm.$children[0].filteredOptions).to.deep.equal(['test', 'production'])
1242+
expect(vm.$children[0].filteredOptions.length).to.equal(2)
1243+
vm.$children[0].search = 'test'
1244+
expect(vm.$children[0].filteredOptions).to.deep.equal(['test', 'testing'])
1245+
expect(vm.$children[0].filteredOptions.length).to.equal(2)
1246+
})
12311247
})
12321248

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

0 commit comments

Comments
 (0)