Skip to content

Commit 92b5000

Browse files
author
Damian Dulisz
authored
Merge pull request shentao#108 from boardbang/2.0
localSearch on 2.0
2 parents 2ad0250 + aa806e9 commit 92b5000

File tree

5 files changed

+49
-7
lines changed

5 files changed

+49
-7
lines changed

lib/multiselectMixin.js

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,15 @@ module.exports = {
99
}
1010
},
1111
props: {
12+
/**
13+
* Decide whether to filter the results based on search query.
14+
* Useful for async filtering, where we search through more complex data.
15+
* @type {Boolean}
16+
*/
17+
localSearch: {
18+
type: Boolean,
19+
default: true
20+
},
1221
/**
1322
* Array of available options: Objects, Strings or Integers.
1423
* If array of objects, visible label will default to option.label.
@@ -176,9 +185,11 @@ module.exports = {
176185
let options = this.hideSelected
177186
? this.options.filter(this.isNotSelected)
178187
: this.options
179-
options = this.label
180-
? options.filter((option) => option[this.label].includes(this.search))
181-
: options.filter((option) => option.includes(this.search))
188+
if (this.localSearch) {
189+
options = this.label
190+
? options.filter((option) => option[this.label].includes(this.search))
191+
: options.filter((option) => option.includes(this.search))
192+
}
182193
if (this.taggable && search.length && !this.isExistingOption(search)) {
183194
options.unshift({ isTag: true, label: search })
184195
}

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@
8484
"nightwatch": "^0.8.18",
8585
"node-sass": "^3.4.2",
8686
"ora": "^0.2.0",
87+
"phantomjs-polyfill-includes": "0.0.1",
8788
"phantomjs-prebuilt": "^2.1.3",
8889
"sass-loader": "^3.2.0",
8990
"selenium-server": "^2.53.0",

src/multiselectMixin.js

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,15 @@ module.exports = {
99
}
1010
},
1111
props: {
12+
/**
13+
* Decide whether to filter the results based on search query.
14+
* Useful for async filtering, where we search through more complex data.
15+
* @type {Boolean}
16+
*/
17+
localSearch: {
18+
type: Boolean,
19+
default: true
20+
},
1221
/**
1322
* Array of available options: Objects, Strings or Integers.
1423
* If array of objects, visible label will default to option.label.
@@ -176,9 +185,11 @@ module.exports = {
176185
let options = this.hideSelected
177186
? this.options.filter(this.isNotSelected)
178187
: this.options
179-
options = this.label
180-
? options.filter((option) => option[this.label].includes(this.search))
181-
: options.filter((option) => option.includes(this.search))
188+
if (this.localSearch) {
189+
options = this.label
190+
? options.filter((option) => option[this.label].includes(this.search))
191+
: options.filter((option) => option.includes(this.search))
192+
}
182193
if (this.taggable && search.length && !this.isExistingOption(search)) {
183194
options.unshift({ isTag: true, label: search })
184195
}

test/unit/karma.conf.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,10 @@ module.exports = function (config) {
5151
browsers: ['PhantomJS'],
5252
frameworks: ['mocha', 'sinon-chai'],
5353
reporters: ['spec', 'coverage'],
54-
files: ['./index.js'],
54+
files: [
55+
'../../node_modules/phantomjs-polyfill-includes/includes-polyfill.js',
56+
'./index.js'
57+
],
5558
preprocessors: {
5659
'./index.js': ['webpack', 'sourcemap']
5760
},

test/unit/specs/Multiselect.spec.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1903,6 +1903,22 @@ describe('Multiselect.vue', () => {
19031903
expect(vm.$children[0].filteredOptions).to.deep.equal([{ isTag: true, label: '1' }, 10])
19041904
expect(vm.$children[0].filteredOptions.length).to.equal(2)
19051905
})
1906+
1907+
it('should not alter the available options when :local-search is FALSE', () => {
1908+
const vm = new Vue({
1909+
template: '<multiselect :selected="value" :options="source" :multiple="true" :local-search="false"></multiselect>',
1910+
components: { Multiselect },
1911+
data: {
1912+
value: [],
1913+
source: [10, 20, 30]
1914+
}
1915+
}).$mount()
1916+
expect(vm.$children[0].filteredOptions).to.deep.equal([10, 20, 30])
1917+
expect(vm.$children[0].filteredOptions.length).to.equal(3)
1918+
vm.$children[0].search = 'test'
1919+
expect(vm.$children[0].filteredOptions).to.deep.equal([10, 20, 30])
1920+
expect(vm.$children[0].filteredOptions.length).to.equal(3)
1921+
})
19061922
})
19071923

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

0 commit comments

Comments
 (0)