Skip to content

Commit e690610

Browse files
author
Andy
committed
feat(checkbox): code review
1 parent ed26f09 commit e690610

File tree

2 files changed

+21
-22
lines changed

2 files changed

+21
-22
lines changed

components/checkbox/Checkbox.jsx

+16-10
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@ export default {
1010
name: 'ACheckbox',
1111
inheritAttrs: false,
1212
__ANT_CHECKBOX: true,
13-
model: {
14-
prop: 'checked',
15-
},
1613
props: {
1714
prefixCls: PropTypes.string,
1815
defaultChecked: PropTypes.bool,
@@ -45,6 +42,7 @@ export default {
4542
});
4643
},
4744
},
45+
4846
mounted() {
4947
const { value, checkboxGroupContext: checkboxGroup = {} } = this;
5048
if (checkboxGroup.registerValue) {
@@ -84,7 +82,7 @@ export default {
8482
const { indeterminate, prefixCls: customizePrefixCls, ...restProps } = props;
8583
const getPrefixCls = this.configProvider.getPrefixCls;
8684
const prefixCls = getPrefixCls('checkbox', customizePrefixCls);
87-
const { onMouseenter, onMouseleave, onInput, ...restAttrs } = $attrs;
85+
const { onMouseenter, onMouseleave, onInput, class: className, style, ...restAttrs } = $attrs;
8886
const checkboxProps = {
8987
...restProps,
9088
prefixCls,
@@ -102,16 +100,24 @@ export default {
102100
} else {
103101
checkboxProps.onChange = this.handleChange;
104102
}
105-
const classString = classNames({
106-
[`${prefixCls}-wrapper`]: true,
107-
[`${prefixCls}-wrapper-checked`]: checkboxProps.checked,
108-
[`${prefixCls}-wrapper-disabled`]: checkboxProps.disabled,
109-
});
103+
const classString = classNames(
104+
{
105+
[`${prefixCls}-wrapper`]: true,
106+
[`${prefixCls}-wrapper-checked`]: checkboxProps.checked,
107+
[`${prefixCls}-wrapper-disabled`]: checkboxProps.disabled,
108+
},
109+
className,
110+
);
110111
const checkboxClass = classNames({
111112
[`${prefixCls}-indeterminate`]: indeterminate,
112113
});
113114
return (
114-
<label class={classString} onMouseenter={onMouseenter} onMouseenter={onMouseleave}>
115+
<label
116+
class={classString}
117+
style={style}
118+
onMouseenter={onMouseenter}
119+
onMouseenter={onMouseleave}
120+
>
115121
<VcCheckbox {...checkboxProps} class={checkboxClass} ref="vcCheckbox" />
116122
{children !== undefined && <span>{children}</span>}
117123
</label>

components/checkbox/Group.jsx

+5-12
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,8 @@ export default {
1717
value: PropTypes.array,
1818
options: PropTypes.array.def([]),
1919
disabled: PropTypes.bool,
20-
onChange: PropTypes.func,
21-
},
22-
provide() {
23-
return {
24-
checkboxGroupContext: this,
25-
};
26-
},
27-
setup() {
28-
return {
29-
configProvider: inject('configProvider', ConfigConsumerProps),
30-
checkboxGroupContext: provide('checkboxGroupContext', this),
31-
};
3220
},
21+
3322
data() {
3423
const { value, defaultValue } = this;
3524
return {
@@ -42,6 +31,10 @@ export default {
4231
this.sValue = val || [];
4332
},
4433
},
34+
created() {
35+
(this.configProvider = inject('configProvider', ConfigConsumerProps)),
36+
provide('checkboxGroupContext', this);
37+
},
4538
methods: {
4639
getOptions() {
4740
const { options, $slots } = this;

0 commit comments

Comments
 (0)