Skip to content

Commit

Permalink
fix: Category select field value assignment
Browse files Browse the repository at this point in the history
  • Loading branch information
letehaha committed Aug 29, 2024
1 parent e1b099a commit 6f80e36
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/components/fields/category-select-field.vue
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,9 @@
<script setup lang="ts">
import { ref, Ref, computed, watch, onBeforeUnmount } from "vue";
import { ChevronLeftIcon, ChevronRightIcon } from "lucide-vue-next";
import { CategoryModel } from "shared-types";
import { type FormattedCategory } from "@/common/types";
import { ChevronLeftIcon, ChevronRightIcon } from "lucide-vue-next";
import { cn } from "@/lib/utils";
import { InputField, FieldError, FieldLabel } from "@/components/fields";
Expand Down Expand Up @@ -150,6 +150,19 @@ const emit = defineEmits<{
const selectedValue = ref(props.modelValue || props.values[0]);
const buttonRef = ref<HTMLButtonElement>(null);
watch(
() => props.modelValue,
(value) => {
// Sometimes real value comes with a delay, not immediately. We need to assign it to
// selectedValue with a delay. Yet we need to avoid any risks of infinite loop, so we need to
// compare IDs to only apply this when values differ
if (value.id !== selectedValue.value.id) {
selectedValue.value = value;
}
},
{ deep: true },
);
const levelValues = ref(props.values);
const rootCategories = ref(props.values);
Expand Down

0 comments on commit 6f80e36

Please sign in to comment.