mirror of
https://gitee.com/ant-design-vue/ant-design-vue.git
synced 2024-12-01 03:28:42 +08:00
feat: update radio
This commit is contained in:
parent
109a386c22
commit
48dda04b75
@ -4,11 +4,9 @@ import PropTypes from '../_util/vue-types';
|
||||
import Radio from './Radio';
|
||||
import { getOptionProps, filterEmpty, hasProp, getSlot } from '../_util/props-util';
|
||||
import { ConfigConsumerProps } from '../config-provider';
|
||||
function noop() {}
|
||||
|
||||
export default {
|
||||
name: 'ARadioGroup',
|
||||
inheritAttrs: false,
|
||||
props: {
|
||||
prefixCls: PropTypes.string,
|
||||
defaultValue: PropTypes.any,
|
||||
@ -26,6 +24,7 @@ export default {
|
||||
disabled: Boolean,
|
||||
name: String,
|
||||
buttonStyle: PropTypes.string.def('outline'),
|
||||
onChange: PropTypes.func,
|
||||
},
|
||||
data() {
|
||||
const { value, defaultValue } = this;
|
||||
@ -56,7 +55,6 @@ export default {
|
||||
},
|
||||
},
|
||||
created() {
|
||||
this.configProvider = inject('configProvider', ConfigConsumerProps);
|
||||
this.radioGroupContext = provide('radioGroupContext', this);
|
||||
},
|
||||
methods: {
|
||||
@ -69,7 +67,7 @@ export default {
|
||||
// nextTick for https://github.com/vueComponent/ant-design-vue/issues/1280
|
||||
if (!this.updatingValue && value !== lastValue) {
|
||||
this.updatingValue = true;
|
||||
this.$emit('update:modelValue', value);
|
||||
this.$emit('update:value', value);
|
||||
this.$emit('change', ev);
|
||||
}
|
||||
nextTick(() => {
|
||||
@ -78,7 +76,6 @@ export default {
|
||||
},
|
||||
},
|
||||
render() {
|
||||
const { onMouseenter = noop, onMouseleave = noop, class: className, style, id } = this.$attrs;
|
||||
const props = getOptionProps(this);
|
||||
const { prefixCls: customizePrefixCls, options, buttonStyle } = props;
|
||||
const getPrefixCls = this.configProvider.getPrefixCls;
|
||||
@ -91,7 +88,6 @@ export default {
|
||||
{
|
||||
[`${groupPrefixCls}-${props.size}`]: props.size,
|
||||
},
|
||||
className,
|
||||
);
|
||||
|
||||
let children = filterEmpty(getSlot(this));
|
||||
@ -129,10 +125,6 @@ export default {
|
||||
return (
|
||||
<div
|
||||
class={classString}
|
||||
onMouseenter={onMouseenter}
|
||||
onMouseleave={onMouseleave}
|
||||
style={style}
|
||||
id={id}
|
||||
>
|
||||
{children}
|
||||
</div>
|
||||
|
@ -5,11 +5,8 @@ import classNames from 'classnames';
|
||||
import { getOptionProps } from '../_util/props-util';
|
||||
import { ConfigConsumerProps } from '../config-provider';
|
||||
|
||||
function noop() {}
|
||||
|
||||
export default {
|
||||
name: 'ARadio',
|
||||
inheritAttrs: false,
|
||||
model: {
|
||||
prop: 'checked',
|
||||
},
|
||||
@ -24,6 +21,7 @@ export default {
|
||||
id: String,
|
||||
autoFocus: Boolean,
|
||||
type: PropTypes.string.def('radio'),
|
||||
onChange: PropTypes.func,
|
||||
},
|
||||
setup() {
|
||||
return {
|
||||
@ -43,7 +41,7 @@ export default {
|
||||
this.$emit('update:value', targetChecked);
|
||||
this.$emit('change', event);
|
||||
},
|
||||
onChange(e) {
|
||||
onChange2(e) {
|
||||
this.$emit('change', e);
|
||||
if (this.radioGroupContext && this.radioGroupContext.onRadioChange) {
|
||||
this.radioGroupContext.onRadioChange(e);
|
||||
@ -52,15 +50,8 @@ export default {
|
||||
},
|
||||
|
||||
render() {
|
||||
const { $slots, radioGroupContext: radioGroup, $attrs } = this;
|
||||
const { $slots, radioGroupContext: radioGroup } = this;
|
||||
const props = getOptionProps(this);
|
||||
const {
|
||||
onMouseenter = noop,
|
||||
onMouseleave = noop,
|
||||
class: className,
|
||||
style,
|
||||
...restAttrs
|
||||
} = $attrs;
|
||||
const { prefixCls: customizePrefixCls, ...restProps } = props;
|
||||
const getPrefixCls = this.configProvider.getPrefixCls;
|
||||
const prefixCls = getPrefixCls('radio', customizePrefixCls);
|
||||
@ -68,18 +59,17 @@ export default {
|
||||
const radioProps = {
|
||||
prefixCls,
|
||||
...restProps,
|
||||
...restAttrs,
|
||||
};
|
||||
|
||||
if (radioGroup) {
|
||||
radioProps.name = radioGroup.name;
|
||||
radioProps.onChange = this.onChange;
|
||||
radioProps.onChange = this.onChange2;
|
||||
radioProps.checked = props.value === radioGroup.stateValue;
|
||||
radioProps.disabled = props.disabled || radioGroup.disabled;
|
||||
} else {
|
||||
radioProps.onChange = this.handleChange;
|
||||
}
|
||||
const wrapperClassString = classNames(className, {
|
||||
const wrapperClassString = classNames( {
|
||||
[`${prefixCls}-wrapper`]: true,
|
||||
[`${prefixCls}-wrapper-checked`]: radioProps.checked,
|
||||
[`${prefixCls}-wrapper-disabled`]: radioProps.disabled,
|
||||
@ -88,12 +78,9 @@ export default {
|
||||
return (
|
||||
<label
|
||||
class={wrapperClassString}
|
||||
style={style}
|
||||
onMouseenter={onMouseenter}
|
||||
onMouseleave={onMouseleave}
|
||||
>
|
||||
<VcCheckbox {...radioProps} ref="vcCheckbox" />
|
||||
{$slots.default !== undefined ? <span>{$slots.default()}</span> : null}
|
||||
{$slots.default && <span>{$slots.default()}</span>}
|
||||
</label>
|
||||
);
|
||||
},
|
||||
|
@ -1,7 +1,6 @@
|
||||
import Radio from './Radio';
|
||||
import Group from './Group';
|
||||
import Button from './RadioButton';
|
||||
// import Base from '../base';
|
||||
|
||||
Radio.Group = Group;
|
||||
Radio.Button = Button;
|
||||
|
@ -8,10 +8,6 @@ export default {
|
||||
name: 'Checkbox',
|
||||
mixins: [BaseMixin],
|
||||
inheritAttrs: false,
|
||||
model: {
|
||||
prop: 'checked',
|
||||
event: 'change',
|
||||
},
|
||||
props: initDefaultProps(
|
||||
{
|
||||
prefixCls: PropTypes.string,
|
||||
@ -73,7 +69,7 @@ export default {
|
||||
}
|
||||
this.$forceUpdate(); // change前,维持现有状态
|
||||
e.shiftKey = this.eventShiftKey;
|
||||
this.__emit('change', {
|
||||
const eventObj = {
|
||||
target: {
|
||||
...props,
|
||||
checked: e.target.checked,
|
||||
@ -85,7 +81,9 @@ export default {
|
||||
e.preventDefault();
|
||||
},
|
||||
nativeEvent: e,
|
||||
});
|
||||
};
|
||||
this.$emit('update:checked', eventObj);
|
||||
this.$emit('change', eventObj);
|
||||
this.eventShiftKey = false;
|
||||
},
|
||||
onClick(e) {
|
||||
|
Loading…
Reference in New Issue
Block a user