From f7886c7203730bedf519bc45f5f78726735d3aac Mon Sep 17 00:00:00 2001 From: tjz <415800467@qq.com> Date: Sun, 17 Jun 2018 16:14:49 +0800 Subject: [PATCH] fix: radio `focus` `blur` `autofocus` `mouseenter` `mouseleave` not working --- components/radio/Radio.jsx | 44 +++++++++++++++++++++++++++++++++++--- 1 file changed, 41 insertions(+), 3 deletions(-) diff --git a/components/radio/Radio.jsx b/components/radio/Radio.jsx index 5ba13dd2c..1108412cd 100644 --- a/components/radio/Radio.jsx +++ b/components/radio/Radio.jsx @@ -14,6 +14,7 @@ export default { value: PropTypes.any, name: String, id: String, + autoFocus: Boolean, }, model: { prop: 'checked', @@ -33,6 +34,13 @@ export default { : stateChecked, } }, + mounted () { + this.$nextTick(() => { + if (this.autoFocus) { + this.$refs.input.focus() + } + }) + }, computed: { classes () { const { prefixCls, disabled, stateChecked } = this @@ -78,6 +86,24 @@ export default { }) } }, + focus () { + this.$refs.input.focus() + }, + blur () { + this.$refs.input.blur() + }, + onFocus (e) { + this.$emit('focus', e) + }, + onBlur (e) { + this.$emit('blur', e) + }, + onMouseEnter (e) { + this.$emit('mouseenter', e) + }, + onMouseLeave (e) { + this.$emit('mouseleave', e) + }, }, watch: { checked (val) { @@ -88,13 +114,25 @@ export default { }, }, render () { - const { id, classes, checkboxClass, disabled, prefixCls, stateChecked, handleChange, name, $slots } = this + const { id, classes, checkboxClass, disabled, prefixCls, + stateChecked, handleChange, name, $slots, + onFocus, + onBlur, + onMouseEnter, + onMouseLeave, + } = this return ( -