fix: checkbox

pull/2439/head
tangjinzhou 2020-06-22 22:27:40 +08:00
parent cdefb49580
commit 3d6bffb067
7 changed files with 41 additions and 30 deletions

@ -1 +1 @@
Subproject commit bf1777054fbe55a0d3bbdd037573e3a235137fbb
Subproject commit be126edd50d4d5ac1c7a05eceb8d57d3c1169889

View File

@ -51,3 +51,11 @@ v-model -> v-model:visible
## Steps
v-model -> v-model:current
## checkbox
v-model -> v-model:checked
checkboxGroup
v-model -> v-model:value

View File

@ -2,9 +2,10 @@ import { inject } from 'vue';
import PropTypes from '../_util/vue-types';
import classNames from 'classnames';
import VcCheckbox from '../vc-checkbox';
import hasProp, { getOptionProps } from '../_util/props-util';
import hasProp, { getOptionProps, getSlot } from '../_util/props-util';
import { ConfigConsumerProps } from '../config-provider';
import warning from '../_util/warning';
function noop() {}
export default {
name: 'ACheckbox',
@ -64,7 +65,8 @@ export default {
methods: {
handleChange(event) {
const targetChecked = event.target.checked;
this.$emit('input', targetChecked);
this.$emit('update:checked', targetChecked);
// this.$emit('input', targetChecked);
this.$emit('change', event);
},
focus() {
@ -77,12 +79,19 @@ export default {
render() {
const props = getOptionProps(this);
const { checkboxGroupContext: checkboxGroup, $slots, $attrs } = this;
const children = $slots.default && $slots.default();
const { checkboxGroupContext: checkboxGroup, $attrs } = this;
const children = getSlot(this);
const { indeterminate, prefixCls: customizePrefixCls, ...restProps } = props;
const getPrefixCls = this.configProvider.getPrefixCls;
const prefixCls = getPrefixCls('checkbox', customizePrefixCls);
const { onMouseenter, onMouseleave, onInput, class: className, style, ...restAttrs } = $attrs;
const {
onMouseenter = noop,
onMouseleave = noop,
onInput,
class: className,
style,
...restAttrs
} = $attrs;
const checkboxProps = {
...restProps,
prefixCls,

View File

@ -1,15 +1,12 @@
import { inject, provide } from 'vue';
import PropTypes from '../_util/vue-types';
import Checkbox from './Checkbox';
import hasProp from '../_util/props-util';
import hasProp, { getSlot } from '../_util/props-util';
import { ConfigConsumerProps } from '../config-provider';
function noop() {}
export default {
name: 'ACheckboxGroup',
model: {
prop: 'value',
},
props: {
name: PropTypes.string,
prefixCls: PropTypes.string,
@ -17,6 +14,7 @@ export default {
value: PropTypes.array,
options: PropTypes.array.def([]),
disabled: PropTypes.bool,
onChange: PropTypes.func,
},
data() {
@ -31,9 +29,13 @@ export default {
this.sValue = val || [];
},
},
setup() {
return {
configProvider: inject('configProvider', ConfigConsumerProps),
};
},
created() {
(this.configProvider = inject('configProvider', ConfigConsumerProps)),
provide('checkboxGroupContext', this);
provide('checkboxGroupContext', this);
},
methods: {
getOptions() {
@ -79,16 +81,17 @@ export default {
const indexB = options.findIndex(opt => opt.value === b);
return indexA - indexB;
});
this.$emit('input', val);
// this.$emit('input', val);
this.$emit('update:value', val);
this.$emit('change', val);
},
},
render() {
const { $props: props, $data: state, $slots } = this;
const { $props: props, $data: state } = this;
const { prefixCls: customizePrefixCls, options } = props;
const getPrefixCls = this.configProvider.getPrefixCls;
const prefixCls = getPrefixCls('checkbox', customizePrefixCls);
let children = $slots.default;
let children = getSlot(this);
const groupPrefixCls = `${prefixCls}-group`;
if (options && options.length > 0) {
children = this.getOptions().map(option => (

View File

@ -1,6 +1,7 @@
import { inject } from 'vue';
import PropTypes from '../_util/vue-types';
import { ConfigConsumerProps } from '../config-provider';
import { getSlot } from '../_util/props-util';
const stringOrNumber = PropTypes.oneOfType([PropTypes.string, PropTypes.number]);
@ -39,16 +40,7 @@ export default {
};
},
render() {
const {
span,
order,
offset,
push,
pull,
prefixCls: customizePrefixCls,
$slots,
rowContext,
} = this;
const { span, order, offset, push, pull, prefixCls: customizePrefixCls, rowContext } = this;
const getPrefixCls = this.configProvider.getPrefixCls;
const prefixCls = getPrefixCls('col', customizePrefixCls);
@ -104,6 +96,6 @@ export default {
};
}
}
return <div {...divProps}>{$slots.default && $slots.default()}</div>;
return <div {...divProps}>{getSlot(this)}</div>;
},
};

View File

@ -3,6 +3,7 @@ import PropTypes from '../_util/vue-types';
import BaseMixin from '../_util/BaseMixin';
import { ConfigConsumerProps } from '../config-provider';
import ResponsiveObserve from '../_util/responsiveObserve';
import { getSlot } from '../_util/props-util';
const RowProps = {
gutter: PropTypes.oneOfType([PropTypes.object, PropTypes.number, PropTypes.array]),
@ -79,7 +80,7 @@ export default {
},
render() {
const { type, justify, align, prefixCls: customizePrefixCls, $slots } = this;
const { type, justify, align, prefixCls: customizePrefixCls } = this;
const getPrefixCls = this.configProvider.getPrefixCls;
const prefixCls = getPrefixCls('row', customizePrefixCls);
@ -106,7 +107,7 @@ export default {
};
return (
<div class={classes} style={rowStyle}>
{$slots.default && $slots.default()}
{getSlot(this)}
</div>
);
},

View File

@ -45,6 +45,4 @@ const Number = (_, { attrs }) => {
return <span class={`${prefixCls}-content-value`}>{valueNode}</span>;
};
Number.name = 'AStatisticNumber';
export default Number;