feat: establish shared field and form foundation
This commit is contained in:
@@ -1,17 +1,12 @@
|
||||
<script setup lang="ts">
|
||||
import { inject, onBeforeUnmount, useId, useAttrs } from "vue";
|
||||
import { switchKey } from "../switch/context";
|
||||
const ctx = inject(switchKey, undefined);
|
||||
import { useAttrs } from "vue";
|
||||
import { useFieldPart } from "../field/useFieldPart";
|
||||
defineOptions({ inheritAttrs: false });
|
||||
const attrs = useAttrs();
|
||||
const id = String(attrs.id ?? useId());
|
||||
if (ctx) ctx.descriptionIds.value = [...ctx.descriptionIds.value, id];
|
||||
onBeforeUnmount(() => {
|
||||
if (ctx)
|
||||
ctx.descriptionIds.value = ctx.descriptionIds.value.filter(
|
||||
(value) => value !== id,
|
||||
);
|
||||
});
|
||||
const { id } = useFieldPart("description", attrs);
|
||||
</script>
|
||||
<template>
|
||||
<p :id="id" class="hv-description" data-slot="description"><slot /></p>
|
||||
<p v-bind="attrs" :id="id" class="hv-description" data-slot="description">
|
||||
<slot />
|
||||
</p>
|
||||
</template>
|
||||
|
||||
Reference in New Issue
Block a user