[bugfix] Radio: can't select when click gap (#4007)

This commit is contained in:
neverland 2019-07-30 20:44:02 +08:00 committed by GitHub
parent cabd3c0f14
commit 4d8c4df5fe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 27 deletions

View File

@ -45,18 +45,6 @@ export default createComponent({
});
},
onClickIcon() {
if (!this.isDisabled) {
this.toggle();
}
},
onClickLabel() {
if (!this.isDisabled && !this.labelDisabled) {
this.toggle();
}
},
setParentValue(val) {
const { parent } = this;
const value = parent.value.slice();

View File

@ -46,6 +46,20 @@ export const CheckboxMixin = ({ parent, bem, role }) => ({
}
},
methods: {
onClick(event) {
const { label } = this.$refs;
const { target } = event;
const labelClicked = label && (label === target || label.contains(target));
if (!this.disabled && !(labelClicked && this.labelDisabled)) {
this.toggle();
}
this.$emit('click', event);
}
},
render() {
const { slots, checked } = this;
@ -55,8 +69,8 @@ export const CheckboxMixin = ({ parent, bem, role }) => ({
const Label = slots() && (
<span
ref="label"
class={bem('label', [this.labelPosition, { disabled: this.isDisabled }])}
onClick={this.onClickLabel}
>
{slots()}
</span>
@ -66,7 +80,6 @@ export const CheckboxMixin = ({ parent, bem, role }) => ({
<div
class={bem('icon', [this.shape, { disabled: this.isDisabled, checked }])}
style={{ fontSize: addUnit(this.iconSize) }}
onClick={this.onClickIcon}
>
{CheckIcon}
</div>
@ -84,9 +97,7 @@ export const CheckboxMixin = ({ parent, bem, role }) => ({
class={bem()}
tabindex={this.tabindex}
aria-checked={String(this.checked)}
onClick={event => {
this.$emit('click', event);
}}
onClick={this.onClick}
>
{Children}
</div>

View File

@ -27,16 +27,8 @@ export default createComponent({
},
methods: {
onClickIcon() {
if (!this.isDisabled) {
this.currentValue = this.name;
}
},
onClickLabel() {
if (!this.isDisabled && !this.labelDisabled) {
this.currentValue = this.name;
}
toggle() {
this.currentValue = this.name;
}
}
});