Fixed Checkbox state in MultiSelect

pull/6632/head
Mert Sincan 2024-10-22 10:40:03 +01:00
parent 06f9b5f630
commit 827b8d1914
2 changed files with 14 additions and 6 deletions

View File

@ -49,6 +49,9 @@ export default {
modelValue(newValue) { modelValue(newValue) {
this.d_value = newValue; this.d_value = newValue;
}, },
defaultValue(newValue) {
this.d_value = newValue;
},
formControl: { formControl: {
immediate: true, immediate: true,
handler(newValue) { handler(newValue) {
@ -66,11 +69,13 @@ export default {
methods: { methods: {
updateValue(value, event) { updateValue(value, event) {
// uncontrolled // uncontrolled
this.d_value = value; if (this.uncontolled) {
this.$emit('value-change', value); this.$emit('value-change', value);
} else {
// controlled // controlled
this.d_value = value;
this.$emit('update:modelValue', value); this.$emit('update:modelValue', value);
}
this.formField.onChange?.({ originalEvent: event, value }); this.formField.onChange?.({ originalEvent: event, value });
} }
@ -85,6 +90,9 @@ export default {
$formName() { $formName() {
return this.formControl?.name || this.name; return this.formControl?.name || this.name;
}, },
uncontolled() {
return this.defaultValue !== undefined && this.modelValue === undefined;
},
// @deprecated use $filled instead // @deprecated use $filled instead
filled() { filled() {
return this.$filled; return this.$filled;

View File

@ -156,7 +156,7 @@
:data-p-focused="focusedOptionIndex === getOptionIndex(i, getItemOptions)" :data-p-focused="focusedOptionIndex === getOptionIndex(i, getItemOptions)"
:data-p-disabled="isOptionDisabled(option)" :data-p-disabled="isOptionDisabled(option)"
> >
<Checkbox :modelValue="isSelected(option)" :binary="true" :tabindex="-1" :variant="variant" :unstyled="unstyled" :pt="getCheckboxPTOptions(option, getItemOptions, i, 'pcOptionCheckbox')"> <Checkbox :defaultValue="isSelected(option)" :binary="true" :tabindex="-1" :variant="variant" :unstyled="unstyled" :pt="getCheckboxPTOptions(option, getItemOptions, i, 'pcOptionCheckbox')">
<template #icon="slotProps"> <template #icon="slotProps">
<component v-if="$slots.optioncheckboxicon || $slots.itemcheckboxicon" :is="$slots.optioncheckboxicon || $slots.itemcheckboxicon" :checked="slotProps.checked" :class="slotProps.class" /> <component v-if="$slots.optioncheckboxicon || $slots.itemcheckboxicon" :is="$slots.optioncheckboxicon || $slots.itemcheckboxicon" :checked="slotProps.checked" :class="slotProps.class" />
<component <component