Skip to content

Commit f26822c

Browse files
authored
Merge pull request sagalbot#348 from andywarren86/master
Prevent interaction when component is disabled
2 parents f836eae + d6b8227 commit f26822c

File tree

3 files changed

+40
-18
lines changed

3 files changed

+40
-18
lines changed

dev.html

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,15 @@
99
<!--<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet">-->
1010
<!-- <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.0.0-alpha.6/css/bootstrap.min.css"> -->
1111
<style>
12-
html,
13-
body,
14-
#app {
15-
height: 100vh;
16-
}
17-
12+
1813
#app {
14+
height: 95vh;
1915
display: flex;
2016
flex-direction: column;
2117
align-items: center;
22-
justify-content: center;
18+
justify-content: flex-start;
19+
flex-wrap: wrap;
20+
align-content: center;
2321
}
2422

2523
.v-select {
@@ -50,7 +48,8 @@
5048
{{option.label}} ({{option.value}})
5149
</template>
5250
</v-select>
53-
<v-select disabled placeholder="disabled" value="Some Selected Value"></v-select>
51+
<v-select disabled placeholder="disabled" value="disabled"></v-select>
52+
<v-select disabled multiple placeholder="disabled" :value="['disabled', 'multiple']"></v-select>
5453
</div>
5554
</body>
5655

src/components/Select.vue

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,6 @@
44
font-family: sans-serif;
55
}
66
7-
.v-select .disabled {
8-
cursor: not-allowed !important;
9-
background-color: rgb(248, 248, 248) !important;
10-
}
11-
127
.v-select,
138
.v-select * {
149
-webkit-box-sizing: border-box;
@@ -246,6 +241,16 @@
246241
width: 5em;
247242
height: 5em;
248243
}
244+
245+
/* Disabled state */
246+
.v-select.disabled .dropdown-toggle,
247+
.v-select.disabled .dropdown-toggle input,
248+
.v-select.disabled .selected-tag .close,
249+
.v-select.disabled .open-indicator {
250+
cursor: not-allowed;
251+
background-color: rgb(248, 248, 248);
252+
}
253+
249254
/* Loading Spinner States */
250255
.v-select.loading .spinner {
251256
opacity: 1;
@@ -280,13 +285,13 @@
280285

281286
<template>
282287
<div :dir="dir" class="dropdown v-select" :class="dropdownClasses">
283-
<div ref="toggle" @mousedown.prevent="toggleDropdown" :class="['dropdown-toggle', 'clearfix', {'disabled': disabled}]">
288+
<div ref="toggle" @mousedown.prevent="toggleDropdown" :class="['dropdown-toggle', 'clearfix']">
284289

285290
<span class="selected-tag" v-for="option in valueAsArray" v-bind:key="option.index">
286291
<slot name="selected-option" v-bind="option">
287292
{{ getOptionLabel(option) }}
288293
</slot>
289-
<button v-if="multiple" @click="deselect(option)" type="button" class="close" aria-label="Remove option">
294+
<button v-if="multiple" :disabled="disabled" @click="deselect(option)" type="button" class="close" aria-label="Remove option">
290295
<span aria-hidden="true">&times;</span>
291296
</button>
292297
</span>
@@ -302,15 +307,16 @@
302307
@blur="onSearchBlur"
303308
@focus="onSearchFocus"
304309
type="search"
305-
:class="[{'disabled': disabled}, 'form-control']"
310+
class="form-control"
311+
:disabled="disabled"
306312
:placeholder="searchPlaceholder"
307313
:readonly="!searchable"
308314
:style="{ width: isValueEmpty ? '100%' : 'auto' }"
309315
:id="inputId"
310316
aria-label="Search for option"
311317
>
312318

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

315321
<slot name="spinner">
316322
<div class="spinner" v-show="mutableLoading">Loading...</div>
@@ -837,7 +843,8 @@
837843
searchable: this.searchable,
838844
unsearchable: !this.searchable,
839845
loading: this.mutableLoading,
840-
rtl: this.dir === 'rtl'
846+
rtl: this.dir === 'rtl',
847+
disabled: this.disabled
841848
}
842849
},
843850

test/unit/specs/Select.spec.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -693,6 +693,22 @@ describe('Select.vue', () => {
693693
})
694694
})
695695

696+
it('should not remove tag when close icon is clicked and component is disabled', (done) => {
697+
const vm = new Vue({
698+
template: '<div><v-select disabled multiple :options="options" v-model="value"></v-select></div>',
699+
components: {vSelect},
700+
data: {
701+
value: ['one'],
702+
options: ['one', 'two', 'three']
703+
}
704+
}).$mount()
705+
vm.$children[0].$refs.toggle.querySelector('.close').click()
706+
Vue.nextTick(() => {
707+
expect(vm.$children[0].mutableValue).toEqual(['one'])
708+
done()
709+
})
710+
})
711+
696712
it('should remove the last item in the value array on delete keypress when multiple is true', () => {
697713

698714
const vm = new Vue({

0 commit comments

Comments
 (0)