mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
fix(Checkbox): bind-group prop not work #7447
This commit is contained in:
parent
2cb5e5e566
commit
ec5684c53e
@ -30,7 +30,10 @@ export default createComponent({
|
|||||||
emit('update:modelValue', []);
|
emit('update:modelValue', []);
|
||||||
} else {
|
} else {
|
||||||
const names = children
|
const names = children
|
||||||
.filter((item) => checked || !item.checked.value)
|
.filter((item) => {
|
||||||
|
const willCheck = checked || !item.checked.value;
|
||||||
|
return item.props.bindGroup && willCheck;
|
||||||
|
})
|
||||||
.map((item) => item.name);
|
.map((item) => item.name);
|
||||||
emit('update:modelValue', names);
|
emit('update:modelValue', names);
|
||||||
}
|
}
|
||||||
|
@ -22,6 +22,7 @@ export default defineComponent({
|
|||||||
role: String,
|
role: String,
|
||||||
parent: Object,
|
parent: Object,
|
||||||
checked: Boolean,
|
checked: Boolean,
|
||||||
|
bindGroup: Boolean,
|
||||||
bem: {
|
bem: {
|
||||||
type: Function,
|
type: Function,
|
||||||
required: true,
|
required: true,
|
||||||
@ -34,7 +35,7 @@ export default defineComponent({
|
|||||||
const iconRef = ref<HTMLElement>();
|
const iconRef = ref<HTMLElement>();
|
||||||
|
|
||||||
const getParentProp = (name: string) => {
|
const getParentProp = (name: string) => {
|
||||||
if (props.parent) {
|
if (props.parent && props.bindGroup) {
|
||||||
return props.parent.props[name];
|
return props.parent.props[name];
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
@ -12,7 +12,6 @@ export const CHECKBOX_KEY = 'vanCheckbox';
|
|||||||
export default createComponent({
|
export default createComponent({
|
||||||
props: {
|
props: {
|
||||||
...checkerProps,
|
...checkerProps,
|
||||||
// TODO
|
|
||||||
bindGroup: {
|
bindGroup: {
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
default: true,
|
default: true,
|
||||||
@ -34,27 +33,33 @@ export default createComponent({
|
|||||||
|
|
||||||
if (!overlimit && value.indexOf(name) === -1) {
|
if (!overlimit && value.indexOf(name) === -1) {
|
||||||
value.push(name);
|
value.push(name);
|
||||||
parent.emit('update:modelValue', value);
|
|
||||||
|
if (props.bindGroup) {
|
||||||
|
parent.emit('update:modelValue', value);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
const index = value.indexOf(name);
|
const index = value.indexOf(name);
|
||||||
|
|
||||||
if (index !== -1) {
|
if (index !== -1) {
|
||||||
value.splice(index, 1);
|
value.splice(index, 1);
|
||||||
parent.emit('update:modelValue', value);
|
|
||||||
|
if (props.bindGroup) {
|
||||||
|
parent.emit('update:modelValue', value);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const checked = computed(() => {
|
const checked = computed(() => {
|
||||||
if (parent) {
|
if (parent && props.bindGroup) {
|
||||||
return parent.props.modelValue.indexOf(props.name) !== -1;
|
return parent.props.modelValue.indexOf(props.name) !== -1;
|
||||||
}
|
}
|
||||||
return props.modelValue;
|
return props.modelValue;
|
||||||
});
|
});
|
||||||
|
|
||||||
const toggle = (newValue = !checked.value) => {
|
const toggle = (newValue = !checked.value) => {
|
||||||
if (parent) {
|
if (parent && props.bindGroup) {
|
||||||
setParentValue(newValue);
|
setParentValue(newValue);
|
||||||
} else {
|
} else {
|
||||||
emit('update:modelValue', newValue);
|
emit('update:modelValue', newValue);
|
||||||
@ -68,7 +73,7 @@ export default createComponent({
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
useExpose({ toggle, checked });
|
useExpose({ toggle, props, checked });
|
||||||
useLinkField(() => props.modelValue);
|
useLinkField(() => props.modelValue);
|
||||||
|
|
||||||
return () => (
|
return () => (
|
||||||
@ -78,6 +83,7 @@ export default createComponent({
|
|||||||
role="checkbox"
|
role="checkbox"
|
||||||
parent={parent}
|
parent={parent}
|
||||||
checked={checked.value}
|
checked={checked.value}
|
||||||
|
bindGroup={props.bindGroup}
|
||||||
onToggle={toggle}
|
onToggle={toggle}
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user