Skip to content

Commit d1e6fdd

Browse files
authored
Merge branch 'master' into master
2 parents f936c80 + 50f9bcc commit d1e6fdd

File tree

7 files changed

+67
-16
lines changed

7 files changed

+67
-16
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ You may now use the component in your markup
5151
Just include `vue` & `vue-select.js` - I recommend using [unpkg](https://unpkg.com/#/).
5252

5353
```html
54-
<script scr="https://unpkg.com/vue@latest"></script>
54+
<script src="https://unpkg.com/vue@latest"></script>
5555
<!-- use the latest release -->
5656
<script src="https://unpkg.com/vue-select@latest"></script>
5757
<!-- or point to a specific release -->

dev.html

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,17 @@
4040
<v-select placeholder="multiple, closeOnSelect=false" multiple :close-on-select="false" :options="['cat', 'dog', 'bear']"></v-select>
4141
<v-select placeholder="unsearchable" :options="options" :searchable="false"></v-select>
4242
<v-select placeholder="search github.." label="full_name" @search="search" :options="ajaxRes"></v-select>
43+
<v-select placeholder="custom option template" :options="options" multiple>
44+
<template slot="selected-option" scope="option">
45+
<img :src='"https://www.kidlink.org/icons/f0-" + option.value.toLowerCase() + ".gif"'/>
46+
{{option.label}}
47+
</template>
48+
<template slot="option" scope="option">
49+
<img :src='"https://www.kidlink.org/icons/f0-" + option.value.toLowerCase() + ".gif"'/>
50+
{{option.label}} ({{option.value}})
51+
</template>
52+
</v-select>
53+
<v-select disabled placeholder="disabled" value="Some Selected Value"></v-select>
4354
</div>
4455
</body>
4556

dist/vue-select.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.

dist/vue-select.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: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"main": "dist/vue-select.js",
88
"license": "MIT",
99
"scripts": {
10+
"start": "npm run dev",
1011
"dev": "node build/dev-server.js",
1112
"dev:docs": "node build/dev-server.js --docs",
1213
"build": "node build/build.js",

src/components/Select.vue

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@
33
position: relative;
44
font-family: sans-serif;
55
}
6+
7+
.v-select .disabled {
8+
cursor: not-allowed !important;
9+
background-color: rgb(248, 248, 248) !important;
10+
}
11+
612
.v-select,
713
.v-select * {
814
-webkit-box-sizing: border-box;
@@ -33,7 +39,6 @@
3339
transition: all 150ms cubic-bezier(1.000, -0.115, 0.975, 0.855);
3440
transition-timing-function: cubic-bezier(1.000, -0.115, 0.975, 0.855);
3541
opacity: 1;
36-
transition: opacity .1s;
3742
height: 20px; width: 10px;
3843
}
3944
.v-select .open-indicator:before {
@@ -71,7 +76,6 @@
7176
border: 1px solid rgba(60, 60, 60, .26);
7277
border-radius: 4px;
7378
white-space: normal;
74-
transition: border-radius .25s;
7579
}
7680
.v-select .dropdown-toggle:after {
7781
visibility: hidden;
@@ -280,10 +284,12 @@
280284

281285
<template>
282286
<div class="dropdown v-select" :class="dropdownClasses">
283-
<div ref="toggle" @mousedown.prevent="toggleDropdown" class="dropdown-toggle">
287+
<div ref="toggle" @mousedown.prevent="toggleDropdown" :class="['dropdown-toggle', 'clearfix', {'disabled': disabled}]">
284288

285289
<span class="selected-tag" v-for="option in valueAsArray" v-bind:key="option.index">
286-
{{ getOptionLabel(option) }}
290+
<slot name="selected-option" v-bind="option">
291+
{{ getOptionLabel(option) }}
292+
</slot>
287293
<button v-if="multiple" @click="deselect(option)" type="button" class="close" aria-label="Remove option">
288294
<span aria-hidden="true">&times;</span>
289295
</button>
@@ -300,15 +306,15 @@
300306
@blur="onSearchBlur"
301307
@focus="onSearchFocus"
302308
type="search"
303-
class="form-control"
309+
:class="[{'disabled': disabled}, 'form-control']"
304310
:placeholder="searchPlaceholder"
305311
:readonly="!searchable"
306312
:style="{ width: isValueEmpty ? '100%' : 'auto' }"
307313
:id="inputId"
308314
aria-label="Search for option"
309315
>
310316

311-
<i v-if="!noDrop" ref="openIndicator" role="presentation" class="open-indicator"></i>
317+
<i v-if="!noDrop" ref="openIndicator" role="presentation" :class="[{'disabled': disabled}, 'open-indicator']"></i>
312318

313319
<slot name="spinner">
314320
<div class="spinner" v-show="mutableLoading">Loading...</div>
@@ -319,7 +325,9 @@
319325
<ul ref="dropdownMenu" v-if="dropdownOpen" class="dropdown-menu" :style="{ 'max-height': maxHeight }">
320326
<li v-for="(option, index) in filteredOptions" v-bind:key="index" :class="{ active: isOptionSelected(option), highlight: index === typeAheadPointer }" @mouseover="typeAheadPointer = index">
321327
<a @mousedown.prevent="select(option)">
328+
<slot name="option" v-bind="option">
322329
{{ getOptionLabel(option) }}
330+
</slot>
323331
</a>
324332
</li>
325333
<li v-if="!filteredOptions.length" class="no-options">
@@ -354,7 +362,7 @@
354362
* If you are using an array of objects, vue-select will look for
355363
* a `label` key (ex. [{label: 'This is Foo', value: 'foo'}]). A
356364
* custom label key can be set with the `label` prop.
357-
* @type {Object}
365+
* @type {Array}
358366
*/
359367
options: {
360368
type: Array,
@@ -363,6 +371,15 @@
363371
},
364372
},
365373
374+
/**
375+
* Disable the entire component.
376+
* @type {Boolean}
377+
*/
378+
disabled: {
379+
type: Boolean,
380+
default: false
381+
},
382+
366383
/**
367384
* Sets the max-height property on the dropdown list.
368385
* @deprecated
@@ -384,7 +401,7 @@
384401
385402
/**
386403
* Equivalent to the `multiple` attribute on a `<select>` input.
387-
* @type {Object}
404+
* @type {Boolean}
388405
*/
389406
multiple: {
390407
type: Boolean,
@@ -393,7 +410,7 @@
393410
394411
/**
395412
* Equivalent to the `placeholder` attribute on an `<input>`.
396-
* @type {Object}
413+
* @type {String}
397414
*/
398415
placeholder: {
399416
type: String,
@@ -442,6 +459,7 @@
442459
/**
443460
* Callback to generate the label text. If {option}
444461
* is an object, returns option[this.label] by default.
462+
* @type {Function}
445463
* @param {Object || String} option
446464
* @return {String}
447465
*/
@@ -462,7 +480,7 @@
462480
* value(s) change. When integrating with Vuex, use this callback to trigger
463481
* an action, rather than using :value.sync to retreive the selected value.
464482
* @type {Function}
465-
* @default {null}
483+
* @param {Object || String} val
466484
*/
467485
onChange: {
468486
type: Function,
@@ -693,8 +711,10 @@
693711
if (this.open) {
694712
this.$refs.search.blur() // dropdown will close on blur
695713
} else {
696-
this.open = true
697-
this.$refs.search.focus()
714+
if (!this.disabled) {
715+
this.open = true
716+
this.$refs.search.focus()
717+
}
698718
}
699719
}
700720
},

test/unit/specs/Select.spec.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,25 @@ describe('Select.vue', () => {
315315
})
316316

317317
describe('Toggling Dropdown', () => {
318+
it('should not open the dropdown when the el is clicked but the component is disabled', (done) => {
319+
const vm = new Vue({
320+
template: '<div><v-select :options="options" :value="value" disabled></v-select></div>',
321+
components: {vSelect},
322+
data: {
323+
value: [{label: 'one'}],
324+
options: [{label: 'one'}]
325+
}
326+
}).$mount()
327+
328+
vm.$children[0].toggleDropdown({target: vm.$children[0].$refs.search})
329+
Vue.nextTick(() => {
330+
Vue.nextTick(() => {
331+
expect(vm.$children[0].open).toEqual(false)
332+
done()
333+
})
334+
})
335+
})
336+
318337
it('should open the dropdown when the el is clicked', (done) => {
319338
const vm = new Vue({
320339
template: '<div><v-select :options="options" :value="value"></v-select></div>',

0 commit comments

Comments
 (0)