Skip to content

Commit 6a7dacf

Browse files
committed
fix: radio focus blur autofocus mouseenter mouseleave not working
1 parent 8dd123d commit 6a7dacf

File tree

1 file changed

+41
-3
lines changed

1 file changed

+41
-3
lines changed

components/radio/Radio.jsx

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export default {
1414
value: PropTypes.any,
1515
name: String,
1616
id: String,
17+
autoFocus: Boolean,
1718
},
1819
model: {
1920
prop: 'checked',
@@ -33,6 +34,13 @@ export default {
3334
: stateChecked,
3435
}
3536
},
37+
mounted () {
38+
this.$nextTick(() => {
39+
if (this.autoFocus) {
40+
this.$refs.input.focus()
41+
}
42+
})
43+
},
3644
computed: {
3745
classes () {
3846
const { prefixCls, disabled, stateChecked } = this
@@ -78,6 +86,24 @@ export default {
7886
})
7987
}
8088
},
89+
focus () {
90+
this.$refs.input.focus()
91+
},
92+
blur () {
93+
this.$refs.input.blur()
94+
},
95+
onFocus (e) {
96+
this.$emit('focus', e)
97+
},
98+
onBlur (e) {
99+
this.$emit('blur', e)
100+
},
101+
onMouseEnter (e) {
102+
this.$emit('mouseenter', e)
103+
},
104+
onMouseLeave (e) {
105+
this.$emit('mouseleave', e)
106+
},
81107
},
82108
watch: {
83109
checked (val) {
@@ -88,13 +114,25 @@ export default {
88114
},
89115
},
90116
render () {
91-
const { id, classes, checkboxClass, disabled, prefixCls, stateChecked, handleChange, name, $slots } = this
117+
const { id, classes, checkboxClass, disabled, prefixCls,
118+
stateChecked, handleChange, name, $slots,
119+
onFocus,
120+
onBlur,
121+
onMouseEnter,
122+
onMouseLeave,
123+
} = this
92124
return (
93-
<label class={classes}>
125+
<label
126+
class={classes}
127+
onMouseenter={onMouseEnter}
128+
onMouseleave={onMouseLeave}
129+
>
94130
<span class={checkboxClass}>
95131
<input name={name} type='radio' disabled={disabled}
96132
class={`${prefixCls}-input`} checked={stateChecked}
97-
onChange={handleChange} id={id}
133+
onChange={handleChange} id={id} ref='input'
134+
onFocus={onFocus}
135+
onBlur={onBlur}
98136
/>
99137
<span class={`${prefixCls}-inner`} />
100138
</span>

0 commit comments

Comments
 (0)