Skip to content

Commit 89138eb

Browse files
VdustRmarcosmoura
authored andcommitted
fix(MdSelect): make options in disabled groups un-selectable (#1293)
* fix(MdSelect): make options in disabled groups un-selectable fix #1286 * fix(MdSelect): make multiple selection checkboxes effective * style(MdOption): remove empty lines
1 parent c9a2b9f commit 89138eb

File tree

2 files changed

+23
-13
lines changed

2 files changed

+23
-13
lines changed

src/components/MdField/MdSelect/MdOption.vue

+21-9
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<template>
22
<md-menu-item :class="optionClasses" :disabled="isDisabled" @click="setSelection">
3-
<md-checkbox class="md-primary" v-model="isChecked" v-if="MdSelect.multiple" />
3+
<md-checkbox class="md-primary" v-model="isChecked" v-if="MdSelect.multiple" :disabled="isDisabled" />
44

55
<span class="md-list-item-text" ref="text">
66
<slot />
@@ -52,8 +52,17 @@
5252
}
5353
},
5454
watch: {
55-
inputLabel () {
55+
selectValue () {
5656
this.setIsSelected()
57+
},
58+
isChecked (val) {
59+
if (val === this.isSelected) {
60+
return
61+
}
62+
this.setSelection()
63+
},
64+
isSelected (val) {
65+
this.isChecked = val
5766
}
5867
},
5968
methods: {
@@ -67,17 +76,24 @@
6776
return slot ? slot[0].text.trim() : ''
6877
},
6978
setIsSelected () {
70-
this.isSelected = this.inputLabel === this.getTextContent()
79+
if (!this.isMultiple) {
80+
this.isSelected = this.selectValue === this.value
81+
return
82+
}
83+
if (this.selectValue === undefined) {
84+
this.isSelected = false
85+
return
86+
}
87+
this.isSelected = this.selectValue.includes(this.value)
7188
},
7289
setSingleSelection () {
7390
this.MdSelect.setValue(this.value)
7491
},
7592
setMultipleSelection () {
76-
this.isChecked = !this.isChecked
7793
this.MdSelect.setMultipleValue(this.value)
7894
},
7995
setSelection () {
80-
if (!this.disabled) {
96+
if (!this.isDisabled) {
8197
if (this.isMultiple) {
8298
this.setMultipleSelection()
8399
} else {
@@ -95,10 +111,6 @@
95111
created () {
96112
this.setItem()
97113
this.setIsSelected()
98-
99-
if (this.isMultiple && this.selectValue && this.selectValue.length) {
100-
this.isChecked = this.selectValue.includes(this.value)
101-
}
102114
}
103115
}
104116
</script>

src/components/MdField/MdSelect/MdSelect.vue

+2-4
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@
8989
items: {},
9090
label: null,
9191
multiple: false,
92-
modelValue: this.model,
92+
modelValue: this.localValue,
9393
setValue: this.setValue,
9494
setContent: this.setContent,
9595
setMultipleValue: this.setMultipleValue,
@@ -115,6 +115,7 @@
115115
immediate: true,
116116
handler (val) {
117117
this.setFieldContent()
118+
this.MdSelect.modelValue = this.localValue
118119
this.emitSelected(val)
119120
}
120121
},
@@ -124,9 +125,6 @@
124125
this.MdSelect.multiple = isMultiple
125126
this.$nextTick(() => this.initialLocalValueByDefault())
126127
}
127-
},
128-
model () {
129-
this.MdSelect.modelValue = this.model
130128
}
131129
},
132130
methods: {

0 commit comments

Comments
 (0)