mirror of
https://github.com/tenrok/vue-select.git
synced 2026-06-22 10:30:34 +03:00
Merge pull request #118 from evanslify/master
Add option to disable the entire component
This commit is contained in:
Vendored
+2
-2
File diff suppressed because one or more lines are too long
Vendored
+1
-1
File diff suppressed because one or more lines are too long
@@ -3,12 +3,19 @@
|
|||||||
position: relative;
|
position: relative;
|
||||||
font-family: sans-serif;
|
font-family: sans-serif;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.v-select .disabled {
|
||||||
|
cursor: not-allowed !important;
|
||||||
|
background-color: rgb(248, 248, 248) !important;
|
||||||
|
}
|
||||||
|
|
||||||
.v-select,
|
.v-select,
|
||||||
.v-select * {
|
.v-select * {
|
||||||
-webkit-box-sizing: border-box;
|
-webkit-box-sizing: border-box;
|
||||||
-moz-box-sizing: border-box;
|
-moz-box-sizing: border-box;
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Open Indicator */
|
/* Open Indicator */
|
||||||
.v-select .open-indicator {
|
.v-select .open-indicator {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
@@ -267,7 +274,7 @@
|
|||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div class="dropdown v-select" :class="dropdownClasses">
|
<div class="dropdown v-select" :class="dropdownClasses">
|
||||||
<div ref="toggle" @mousedown.prevent="toggleDropdown" class="dropdown-toggle">
|
<div ref="toggle" @mousedown.prevent="toggleDropdown" :class="['dropdown-toggle', 'clearfix', {'disabled': disabled}]" type="button">
|
||||||
|
|
||||||
<span class="selected-tag" v-for="option in valueAsArray" v-bind:key="option.index">
|
<span class="selected-tag" v-for="option in valueAsArray" v-bind:key="option.index">
|
||||||
<slot name="selected-option" v-bind="option">
|
<slot name="selected-option" v-bind="option">
|
||||||
@@ -289,7 +296,7 @@
|
|||||||
@blur="onSearchBlur"
|
@blur="onSearchBlur"
|
||||||
@focus="onSearchFocus"
|
@focus="onSearchFocus"
|
||||||
type="search"
|
type="search"
|
||||||
class="form-control"
|
:class="[{'disabled': disabled}, 'form-control']"
|
||||||
:placeholder="searchPlaceholder"
|
:placeholder="searchPlaceholder"
|
||||||
:readonly="!searchable"
|
:readonly="!searchable"
|
||||||
:style="{ width: isValueEmpty ? '100%' : 'auto' }"
|
:style="{ width: isValueEmpty ? '100%' : 'auto' }"
|
||||||
@@ -297,7 +304,7 @@
|
|||||||
aria-label="Search for option"
|
aria-label="Search for option"
|
||||||
>
|
>
|
||||||
|
|
||||||
<i v-if="!noDrop" ref="openIndicator" role="presentation" class="open-indicator"></i>
|
<i v-if="!noDrop" ref="openIndicator" role="presentation" :class="[{'disabled': disabled}, 'open-indicator']"></i>
|
||||||
|
|
||||||
<slot name="spinner">
|
<slot name="spinner">
|
||||||
<div class="spinner" v-show="mutableLoading">Loading...</div>
|
<div class="spinner" v-show="mutableLoading">Loading...</div>
|
||||||
@@ -354,6 +361,15 @@
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Disable the entire component.
|
||||||
|
* @type {Boolean}
|
||||||
|
*/
|
||||||
|
disabled: {
|
||||||
|
type: Boolean,
|
||||||
|
default: false
|
||||||
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the max-height property on the dropdown list.
|
* Sets the max-height property on the dropdown list.
|
||||||
* @deprecated
|
* @deprecated
|
||||||
@@ -675,8 +691,10 @@
|
|||||||
if (this.open) {
|
if (this.open) {
|
||||||
this.$refs.search.blur() // dropdown will close on blur
|
this.$refs.search.blur() // dropdown will close on blur
|
||||||
} else {
|
} else {
|
||||||
this.open = true
|
if (!this.disabled) {
|
||||||
this.$refs.search.focus()
|
this.open = true
|
||||||
|
this.$refs.search.focus()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -315,6 +315,25 @@ describe('Select.vue', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
describe('Toggling Dropdown', () => {
|
describe('Toggling Dropdown', () => {
|
||||||
|
it('should not open the dropdown when the el is clicked but the component is disabled', (done) => {
|
||||||
|
const vm = new Vue({
|
||||||
|
template: '<div><v-select :options="options" :value="value" disabled></v-select></div>',
|
||||||
|
components: {vSelect},
|
||||||
|
data: {
|
||||||
|
value: [{label: 'one'}],
|
||||||
|
options: [{label: 'one'}]
|
||||||
|
}
|
||||||
|
}).$mount()
|
||||||
|
|
||||||
|
vm.$children[0].toggleDropdown({target: vm.$children[0].$refs.search})
|
||||||
|
Vue.nextTick(() => {
|
||||||
|
Vue.nextTick(() => {
|
||||||
|
expect(vm.$children[0].open).toEqual(false)
|
||||||
|
done()
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
it('should open the dropdown when the el is clicked', (done) => {
|
it('should open the dropdown when the el is clicked', (done) => {
|
||||||
const vm = new Vue({
|
const vm = new Vue({
|
||||||
template: '<div><v-select :options="options" :value="value"></v-select></div>',
|
template: '<div><v-select :options="options" :value="value"></v-select></div>',
|
||||||
|
|||||||
Reference in New Issue
Block a user