Skip to content

Commit

Permalink
Update uri ref for select component reactivity #147
Browse files Browse the repository at this point in the history
  • Loading branch information
johnatawnclementawn committed Jan 3, 2025
1 parent ecdb34d commit 5787490
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ defineProps<{
options?: ControlledListItem[];
}>();
const emits = defineEmits(["update"]);
const onUpdate = (val: ControlledListItem) => {
const onUpdate = (val: ControlledListItem[]) => {
emits("update", val);
};
</script>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script setup lang="ts">
import { computed, inject, toRef } from "vue";
import { computed, inject, ref } from "vue";
import Select from "primevue/select";
import { systemLanguageKey } from "@/arches_lingo/constants.ts";
Expand All @@ -21,16 +21,15 @@ const props = withDefaults(
);
const emit = defineEmits(["update"]);
const valRef = toRef(props?.value?.[0]?.uri); // use uri as value
const uriRef = ref(props?.value?.[0]?.uri); // unwrap array n=1 && use uri as value
const val = computed({
get() {
return valRef.value; // unwrap array n=1
return uriRef.value;
},
set(value) {
// const item = props.options?.find((item) => item.uri === value);
console.log(value);
// emit("update", [item]); // rewrap array n=1
emit("update", value);
set(newVal) {
uriRef.value = newVal; // update uri
const item = props.options?.find((item) => item.uri === newVal);
emit("update", item ? [item] : []); // emit the updated value as a list item
},
});
Expand Down

0 comments on commit 5787490

Please sign in to comment.