|
@@ -3,14 +3,17 @@
|
|
<div class="el-switch__mask" v-show="disabled"></div>
|
|
<div class="el-switch__mask" v-show="disabled"></div>
|
|
<input
|
|
<input
|
|
class="el-switch__input"
|
|
class="el-switch__input"
|
|
|
|
+ :class="{ 'allow-focus': allowFocus }"
|
|
type="checkbox"
|
|
type="checkbox"
|
|
@change="handleChange"
|
|
@change="handleChange"
|
|
|
|
+ @focus="handleFocus"
|
|
|
|
+ @blur="handleBlur"
|
|
ref="input"
|
|
ref="input"
|
|
:name="name"
|
|
:name="name"
|
|
:true-value="onValue"
|
|
:true-value="onValue"
|
|
:false-value="offValue"
|
|
:false-value="offValue"
|
|
:disabled="disabled">
|
|
:disabled="disabled">
|
|
- <span class="el-switch__core" ref="core" :style="{ 'width': coreWidth + 'px' }">
|
|
|
|
|
|
+ <span class="el-switch__core" ref="core" :style="{ 'width': coreWidth + 'px' }" @click="setFocus">
|
|
<span class="el-switch__button" :style="{ transform }"></span>
|
|
<span class="el-switch__button" :style="{ transform }"></span>
|
|
</span>
|
|
</span>
|
|
<transition name="label-fade">
|
|
<transition name="label-fade">
|
|
@@ -85,6 +88,10 @@
|
|
name: {
|
|
name: {
|
|
type: String,
|
|
type: String,
|
|
default: ''
|
|
default: ''
|
|
|
|
+ },
|
|
|
|
+ allowFocus: {
|
|
|
|
+ type: Boolean,
|
|
|
|
+ default: false
|
|
}
|
|
}
|
|
},
|
|
},
|
|
data() {
|
|
data() {
|
|
@@ -131,6 +138,22 @@
|
|
let newColor = this.checked ? this.onColor : this.offColor;
|
|
let newColor = this.checked ? this.onColor : this.offColor;
|
|
this.$refs.core.style.borderColor = newColor;
|
|
this.$refs.core.style.borderColor = newColor;
|
|
this.$refs.core.style.backgroundColor = newColor;
|
|
this.$refs.core.style.backgroundColor = newColor;
|
|
|
|
+ },
|
|
|
|
+ setFocus() {
|
|
|
|
+ // set focus on input
|
|
|
|
+ if (this.allowFocus) {
|
|
|
|
+ this.$refs.input.focus();
|
|
|
|
+ }
|
|
|
|
+ },
|
|
|
|
+ handleBlur(event) {
|
|
|
|
+ if (this.allowFocus) {
|
|
|
|
+ this.$emit('blur', event);
|
|
|
|
+ }
|
|
|
|
+ },
|
|
|
|
+ handleFocus(event) {
|
|
|
|
+ if (this.allowFocus) {
|
|
|
|
+ this.$emit('focus', event);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
},
|
|
},
|
|
mounted() {
|
|
mounted() {
|