visua-vue/src/components/accordion/VAccordion.vue

46 lines
1.1 KiB
Vue
Raw Normal View History

<script setup lang="ts">
import Accordion from 'primevue/accordion';
import VAccordionChild from './VAccordionChild.vue';
import type IVAccordion from './IVAccordion.type';
2025-07-21 16:22:24 +02:00
import { ref, watch } from 'vue';
const props = withDefaults(defineProps<IVAccordion>(), {
2025-07-21 16:22:24 +02:00
value: null,
});
2025-07-21 17:00:18 +02:00
// Define the event emitter for v-model binding
2025-07-21 16:22:24 +02:00
const emit = defineEmits([
'update:value',
])
2025-07-21 17:00:18 +02:00
// Local reactive value to sync with the parent v-model
2025-07-21 16:22:24 +02:00
const localValue = ref(props.value);
2025-07-21 17:00:18 +02:00
// Watch for external changes to the prop and update localValue accordingly
2025-07-21 16:22:24 +02:00
watch(() => props.value, (newVal) => {
if(localValue.value !== newVal) {
localValue.value = newVal;
}
});
2025-07-21 17:00:18 +02:00
// Watch for internal changes to localValue and emit them to the parent
2025-07-21 16:22:24 +02:00
watch(localValue, (newVal) => {
if(props.value !== newVal){
emit('update:value', newVal);
}
});
</script>
<template>
2025-07-21 16:22:24 +02:00
<Accordion
v-model:value="localValue"
class="p-accordion"
style="width: 100%;"
@update:value="emit('update:value', $event)"
>
<slot>
<VAccordionChild/>
</slot>
</Accordion>
</template>