Skip to content

Commit 2ea337e

Browse files
author
Rajesh Akkineni
committed
Mograted to Vue2.0
1 parent df5827d commit 2ea337e

File tree

1 file changed

+20
-17
lines changed

1 file changed

+20
-17
lines changed

src/components/Select.vue

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -172,17 +172,17 @@
172172

173173
<template>
174174
<div class="dropdown v-select" :class="dropdownClasses">
175-
<div v-el:toggle @mousedown.prevent="toggleDropdown" class="dropdown-toggle clearfix" type="button">
175+
<div ref="toggle" @mousedown.prevent="toggleDropdown" class="dropdown-toggle clearfix" type="button">
176176

177-
<span class="selected-tag" v-for="option in valueAsArray" track-by="$index">
177+
<span class="selected-tag" v-for="(option, index) in valueAsArray" track-by="index">
178178
{{ getOptionLabel(option) }}
179179
<button v-if="multiple" @click="select(option)" type="button" class="close">
180180
<span aria-hidden="true">&times;</span>
181181
</button>
182182
</span>
183183

184184
<input
185-
v-el:search
185+
ref="search"
186186
:debounce="debounce"
187187
v-model="search"
188188
@keydown.delete="maybeDeleteValue"
@@ -199,23 +199,25 @@
199199
:style="{ width: isValueEmpty ? '100%' : 'auto' }"
200200
>
201201

202-
<i v-el:open-indicator role="presentation" class="open-indicator"></i>
202+
<i ref="open-indicator" role="presentation" class="open-indicator"></i>
203203

204204
<slot name="spinner">
205205
<div class="spinner" v-show="loading">Loading...</div>
206206
</slot>
207207
</div>
208208

209-
<ul v-el:dropdown-menu v-show="open" :transition="transition" class="dropdown-menu" :style="{ 'max-height': maxHeight }">
210-
<li v-for="option in filteredOptions" track-by="$index" :class="{ active: isOptionSelected(option), highlight: $index === typeAheadPointer }" @mouseover="typeAheadPointer = $index">
209+
<ul ref="dropdown-menu" v-show="open" :transition="transition" class="dropdown-menu" :style="{ 'max-height': maxHeight }">
210+
<li v-for="(option, index) in filteredOptions" track-by="index" :class="{ active: isOptionSelected(option), highlight: index === typeAheadPointer }" @mouseover="typeAheadPointer = index">
211211
<a @mousedown.prevent="select(option)">
212212
{{ getOptionLabel(option) }}
213213
</a>
214214
</li>
215-
<li transition="fade" v-if="!filteredOptions.length" class="divider"></li>
216-
<li transition="fade" v-if="!filteredOptions.length" class="text-center">
217-
<slot name="no-options">Sorry, no matching options.</slot>
218-
</li>
215+
<transition name="fade">
216+
<li v-if="!filteredOptions.length" class="divider"></li>
217+
<li v-if="!filteredOptions.length" class="text-center">
218+
<slot name="no-options">Sorry, no matching options.</slot>
219+
</li>
220+
</transition>
219221
</ul>
220222
</div>
221223
</template>
@@ -463,7 +465,8 @@
463465
ref = val
464466
}
465467
})
466-
this.value.$remove(ref)
468+
var index = this.value.indexOf(ref)
469+
this.value.splice(index, 1)
467470
} else {
468471
this.value = null
469472
}
@@ -477,7 +480,7 @@
477480
onAfterSelect(option) {
478481
if (!this.multiple) {
479482
this.open = !this.open
480-
this.$els.search.blur()
483+
this.$refs.search.blur()
481484
}
482485
483486
if (this.clearSearchOnSelect) {
@@ -491,12 +494,12 @@
491494
* @return {void}
492495
*/
493496
toggleDropdown(e) {
494-
if (e.target === this.$els.openIndicator || e.target === this.$els.search || e.target === this.$els.toggle || e.target === this.$el) {
497+
if (e.target === this.$refs.openIndicator || e.target === this.$refs.search || e.target === this.$refs.toggle || e.target === this.$el) {
495498
if (this.open) {
496-
this.$els.search.blur() // dropdown will close on blur
499+
this.$refs.search.blur() // dropdown will close on blur
497500
} else {
498501
this.open = true
499-
this.$els.search.focus()
502+
this.$refs.search.focus()
500503
}
501504
}
502505
},
@@ -529,7 +532,7 @@
529532
*/
530533
onEscape() {
531534
if (!this.search.length) {
532-
this.$els.search.blur()
535+
this.$refs.search.blur()
533536
} else {
534537
this.search = ''
535538
}
@@ -541,7 +544,7 @@
541544
* @return {this.value}
542545
*/
543546
maybeDeleteValue() {
544-
if (!this.$els.search.value.length && this.value) {
547+
if (!this.$refs.search.value.length && this.value) {
545548
return this.multiple ? this.value.pop() : this.$set('value', null)
546549
}
547550
},

0 commit comments

Comments
 (0)