Skip to content

Commit 1fc8079

Browse files
author
Damian Dulisz
committed
[2.0.0] beta.1 release
* Might be very unstable * Didn’t manage to fix all the tests yet
1 parent 1031858 commit 1fc8079

File tree

10 files changed

+864
-112
lines changed

10 files changed

+864
-112
lines changed

docs/index.jade

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ html(lang="en")
1717
body
1818
#app
1919
//- include ./partials/_start
20-
//-
20+
2121
//- .grid__row.docs
2222
//- .grid__columns.grid__unit--sm-3.small--hidden
2323
//- include ./partials/_nav
@@ -54,7 +54,7 @@ html(lang="en")
5454
//- include ./partials/api/_props
5555
//- include ./partials/api/_events
5656
//- include ./partials/api/_slots
57-
//-
57+
5858
//- include ./partials/_footer
5959
6060
//- script(src='static/prism.js')

docs/main.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import Vue from 'vue'
22

3+
// require('./docs.scss')
4+
35
import App from './App'
46

57
/* eslint-disable no-new */

lib/Multiselect.vue

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,10 @@
1010
@keyup.esc="deactivate()"
1111
class="multiselect">
1212
<div @mousedown.prevent="toggle()" class="multiselect__select"></div>
13-
<div v-el:tags class="multiselect__tags">
13+
<div ref="tags" class="multiselect__tags">
1414
<span
1515
v-if="multiple"
16-
v-for="option in visibleValue"
17-
track-by="$index"
16+
v-for="option of visibleValue"
1817
onmousedown="event.preventDefault()"
1918
class="multiselect__tag">
2019
<span v-text="getOptionLabel(option)"></span>
@@ -29,15 +28,14 @@
2928
<template v-if="value && value.length > limit">
3029
<strong v-text="limitText(value.length - limit)"></strong>
3130
</template>
32-
<div v-show="loading" transition="multiselect__loading" class="multiselect__spinner"></div>
31+
<div v-show="loading" class="multiselect__spinner"></div>
3332
<input
3433
name="search"
3534
type="text"
3635
autocomplete="off"
3736
:placeholder="placeholder"
38-
v-el:search
3937
v-if="searchable"
40-
v-model="search"
38+
v-model.trim="search"
4139
:disabled="disabled"
4240
@focus.prevent="activate()"
4341
@blur.prevent="deactivate()"
@@ -54,9 +52,8 @@
5452
</span>
5553
</div>
5654
<ul
57-
transition="multiselect"
5855
:style="{ maxHeight: maxHeight + 'px' }"
59-
v-el:list
56+
ref="list"
6057
v-show="isOpen"
6158
class="multiselect__content">
6259
<slot name="beforeList"></slot>
@@ -66,17 +63,21 @@
6663
</span>
6764
</li>
6865
<template v-if="!max || value.length < max">
69-
<li v-for="option in filteredOptions" track-by="$index">
66+
<li v-for="(option, index) of filteredOptions" :key="index">
7067
<span
7168
tabindex="0"
72-
:class="{ 'multiselect__option--highlight': $index === pointer && this.showPointer, 'multiselect__option--selected': !isNotSelected(option) }"
69+
:class="optionHighlight(index, option)"
7370
@mousedown.prevent="select(option)"
74-
@mouseenter="pointerSet($index)"
71+
@mouseenter="pointerSet(index)"
7572
:data-select="option.isTag ? tagPlaceholder : selectLabel"
7673
:data-selected="selectedLabel"
7774
:data-deselect="deselectLabel"
78-
class="multiselect__option"
79-
v-text="getOptionLabel(option)">
75+
class="multiselect__option">
76+
<multiselect-option
77+
:option-function="optionFunction"
78+
:label="getOptionLabel(option)"
79+
:option="option">
80+
</multiselect-option>
8081
</span>
8182
</li>
8283
</template>
@@ -86,15 +87,19 @@
8687
</span>
8788
</li>
8889
<slot name="afterList"></slot>
89-
</ul>
90+
</ul>
9091
</div>
9192
</template>
9293

9394
<script>
9495
import multiselectMixin from './multiselectMixin'
9596
import pointerMixin from './pointerMixin'
97+
import MultiselectOption from './MultiselectOption'
9698
9799
export default {
100+
components: {
101+
MultiselectOption
102+
},
98103
mixins: [multiselectMixin, pointerMixin],
99104
props: {
100105
/**
@@ -170,6 +175,12 @@
170175
disabled: {
171176
type: Boolean,
172177
default: false
178+
},
179+
optionFunction: {
180+
type: Function,
181+
default (h, option, label) {
182+
return h('span', {}, label)
183+
}
173184
}
174185
},
175186
computed: {
@@ -179,7 +190,7 @@
179190
: this.value
180191
}
181192
},
182-
ready () {
193+
mounted () {
183194
/* istanbul ignore else */
184195
if (!this.showLabels) {
185196
this.deselectLabel = this.selectedLabel = this.selectLabel = ''

lib/multiselectMixin.js

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import deepClone from './utils'
2-
import Vue from 'vue'
32

43
module.exports = {
54
data () {
@@ -40,17 +39,15 @@ module.exports = {
4039
* @type {String}
4140
*/
4241
key: {
43-
type: String,
44-
default: false
42+
type: String
4543
},
4644
/**
4745
* Label to look for in option Object
4846
* @default 'label'
4947
* @type {String}
5048
*/
5149
label: {
52-
type: String,
53-
default: false
50+
type: String
5451
},
5552
/**
5653
* Enable/disable search in options
@@ -132,8 +129,7 @@ module.exports = {
132129
* @type {Function}
133130
*/
134131
customLabel: {
135-
type: Function,
136-
default: false
132+
type: Function
137133
},
138134
/**
139135
* Disable / Enable tagging
@@ -159,8 +155,7 @@ module.exports = {
159155
* @type {Number}
160156
*/
161157
max: {
162-
type: Number,
163-
default: false
158+
type: Number
164159
},
165160
/**
166161
* Will be passed with all events as second param.
@@ -181,7 +176,9 @@ module.exports = {
181176
let options = this.hideSelected
182177
? this.options.filter(this.isNotSelected)
183178
: this.options
184-
options = this.$options.filters.filterBy(options, this.search)
179+
options = this.label
180+
? options.filter((option) => option[this.label].indexOf(this.search) !== -1)
181+
: options.filter((option) => option.indexOf(this.search) !== -1)
185182
if (this.taggable && search.length && !this.isExistingOption(search)) {
186183
options.unshift({ isTag: true, label: search })
187184
}
@@ -208,9 +205,9 @@ module.exports = {
208205
watch: {
209206
'value' () {
210207
if (this.resetAfter) {
211-
Vue.set('value', null)
212-
Vue.set('search', null)
213-
Vue.set('selected', null)
208+
this.$set('value', null)
209+
this.$set('search', null)
210+
this.$set('selected', null)
214211
}
215212
this.adjustSearch()
216213
},
@@ -340,7 +337,8 @@ module.exports = {
340337
const index = this.valueKeys.indexOf(option[this.key])
341338
this.value.splice(index, 1)
342339
} else {
343-
this.value.$remove(option)
340+
const index = this.valueKeys.indexOf(option)
341+
this.value.splice(index, 1)
344342
}
345343
this.$emit('remove', deepClone(option), this.id)
346344
this.$emit('update', deepClone(this.value), this.id)
@@ -369,7 +367,7 @@ module.exports = {
369367
/* istanbul ignore else */
370368
if (this.searchable) {
371369
this.search = ''
372-
this.$refs.search.focus()
370+
this.$el.children[1].children[2].focus()
373371
} else {
374372
this.$el.focus()
375373
}
@@ -386,7 +384,7 @@ module.exports = {
386384
this.isOpen = false
387385
/* istanbul ignore else */
388386
if (this.searchable) {
389-
this.$refs.search.blur()
387+
this.$el.children[1].children[2].blur()
390388
this.adjustSearch()
391389
} else {
392390
this.$el.blur()

lib/pointerMixin.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@ module.exports = {
2727
}
2828
},
2929
methods: {
30+
optionHighlight (index, option) {
31+
return {
32+
'multiselect__option--highlight': index === this.pointer && this.showPointer,
33+
'multiselect__option--selected': !this.isNotSelected(option)
34+
}
35+
},
3036
addPointerElement () {
3137
if (this.filteredOptions.length > 0) {
3238
this.select(this.filteredOptions[this.pointer])

lib/vue-multiselect.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/vue-multiselect.min.js.map

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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "vue-multiselect",
3-
"version": "1.0.1",
3+
"version": "2.0.0-beta.1",
44
"description": "Multiselect component for vue.js",
55
"author": "Damian Dulisz <damian.dulisz@monterail.com>",
66
"private": false,
@@ -91,7 +91,7 @@
9191
"sinon": "^1.17.3",
9292
"sinon-chai": "^2.8.0",
9393
"url-loader": "^0.5.7",
94-
"vue": "^2.0.0-rc.1",
94+
"vue": "^2.0.0-rc.3",
9595
"vue-hot-reload-api": "^1.2.0",
9696
"vue-html-loader": "^1.0.0",
9797
"vue-loader": "^9.3.2",

src/multiselectMixin.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,8 +177,8 @@ module.exports = {
177177
? this.options.filter(this.isNotSelected)
178178
: this.options
179179
options = this.label
180-
? options.filter((option) => option[this.label].includes(this.search))
181-
: options.filter((option) => option.includes(this.search))
180+
? options.filter((option) => option[this.label].indexOf(this.search) !== -1)
181+
: options.filter((option) => option.indexOf(this.search) !== -1)
182182
if (this.taggable && search.length && !this.isExistingOption(search)) {
183183
options.unshift({ isTag: true, label: search })
184184
}

0 commit comments

Comments
 (0)