From 14e7805af1fbabe72ce7038f02658fd9eda0b216 Mon Sep 17 00:00:00 2001
From: tjz <415800467@qq.com>
Date: Sun, 20 May 2018 21:41:40 +0800
Subject: [PATCH] fix: checkbox add focus blur events & autoFocus
---
components/checkbox/Checkbox.jsx | 22 +++++++++++++++++++++-
1 file changed, 21 insertions(+), 1 deletion(-)
diff --git a/components/checkbox/Checkbox.jsx b/components/checkbox/Checkbox.jsx
index f9508a8c3..b8bc6fe12 100644
--- a/components/checkbox/Checkbox.jsx
+++ b/components/checkbox/Checkbox.jsx
@@ -17,6 +17,7 @@ export default {
name: String,
indeterminate: Boolean,
type: PropTypes.string.def('checkbox'),
+ autoFocus: Boolean,
},
model: {
prop: 'checked',
@@ -24,6 +25,13 @@ export default {
inject: {
checkboxGroupContext: { default: null },
},
+ mounted () {
+ this.$nextTick(() => {
+ if (this.autoFocus) {
+ this.$refs.input.focus()
+ }
+ })
+ },
data () {
const { checkboxGroupContext, checked, defaultChecked, value } = this
let sChecked
@@ -85,6 +93,12 @@ export default {
blur () {
this.$refs.input.blur()
},
+ onFocus (e) {
+ this.$emit('focus', e)
+ },
+ onBlur (e) {
+ this.$emit('blur', e)
+ },
},
watch: {
checked (val) {
@@ -95,7 +109,11 @@ export default {
},
},
render () {
- const { $props: props, checkboxGroupContext, checkboxClass, name, $slots, sChecked } = this
+ const { $props: props, checkboxGroupContext,
+ checkboxClass, name, $slots, sChecked,
+ onFocus,
+ onBlur,
+ } = this
const {
prefixCls,
} = props
@@ -119,6 +137,8 @@ export default {