Fix error with inject/provide
This commit is contained in:
parent
caa1010bc7
commit
7b3d625a22
|
|
@ -1,16 +1,35 @@
|
|||
<script lang="ts" setup>
|
||||
import { Slot } from 'radix-vue'
|
||||
import { useFormField } from './useFormField'
|
||||
import { Slot } from "radix-vue";
|
||||
import { useFormField } from "./useFormField";
|
||||
|
||||
const { error, formItemId, formDescriptionId, formMessageId } = useFormField()
|
||||
const props = defineProps<{
|
||||
label?: string;
|
||||
description?: string;
|
||||
}>();
|
||||
|
||||
const { error, formItemId, formDescriptionId, formMessageId } = useFormField();
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<FormLabel v-if="props.label">{{ props.label }}</FormLabel>
|
||||
|
||||
<Slot
|
||||
:id="formItemId"
|
||||
:aria-describedby="!error ? `${formDescriptionId}` : `${formDescriptionId} ${formMessageId}`"
|
||||
:aria-describedby="
|
||||
!error
|
||||
? `${formDescriptionId}`
|
||||
: props.description
|
||||
? `${formMessageId}`
|
||||
: `${formDescriptionId} ${formMessageId}`
|
||||
"
|
||||
:aria-invalid="!!error"
|
||||
>
|
||||
<slot />
|
||||
</Slot>
|
||||
|
||||
<FormDescription v-if="props.description && !error">
|
||||
{{ props.description }}
|
||||
</FormDescription>
|
||||
|
||||
<FormMessage v-if="props.description" />
|
||||
</template>
|
||||
|
|
|
|||
|
|
@ -3,30 +3,17 @@ import { cn } from "@/lib/utils";
|
|||
import { useId } from "radix-vue";
|
||||
import { type HTMLAttributes, provide } from "vue";
|
||||
import { FORM_ITEM_INJECTION_KEY } from "./injectionKeys";
|
||||
import { useFormField } from "./useFormField";
|
||||
|
||||
const props = defineProps<{
|
||||
class?: HTMLAttributes["class"];
|
||||
label?: string;
|
||||
description?: string;
|
||||
}>();
|
||||
|
||||
const { error } = useFormField();
|
||||
|
||||
const id = useId();
|
||||
provide(FORM_ITEM_INJECTION_KEY, id);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div :class="cn('space-y-2', props.class)">
|
||||
<FormLabel v-if="props.label">{{ props.label }}</FormLabel>
|
||||
|
||||
<slot />
|
||||
|
||||
<FormDescription v-if="props.description && !error">
|
||||
{{ props.description }}
|
||||
</FormDescription>
|
||||
|
||||
<FormMessage v-if="props.description" />
|
||||
</div>
|
||||
</template>
|
||||
|
|
|
|||
|
|
@ -1,16 +1,35 @@
|
|||
<script lang="ts" setup>
|
||||
import { Slot } from 'radix-vue'
|
||||
import { useFormField } from './useFormField'
|
||||
import { Slot } from "radix-vue";
|
||||
import { useFormField } from "./useFormField";
|
||||
|
||||
const { error, formItemId, formDescriptionId, formMessageId } = useFormField()
|
||||
const props = defineProps<{
|
||||
label?: string;
|
||||
description?: string;
|
||||
}>();
|
||||
|
||||
const { error, formItemId, formDescriptionId, formMessageId } = useFormField();
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<FormLabel v-if="props.label">{{ props.label }}</FormLabel>
|
||||
|
||||
<Slot
|
||||
:id="formItemId"
|
||||
:aria-describedby="!error ? `${formDescriptionId}` : `${formDescriptionId} ${formMessageId}`"
|
||||
:aria-describedby="
|
||||
!error
|
||||
? `${formDescriptionId}`
|
||||
: props.description
|
||||
? `${formMessageId}`
|
||||
: `${formDescriptionId} ${formMessageId}`
|
||||
"
|
||||
:aria-invalid="!!error"
|
||||
>
|
||||
<slot />
|
||||
</Slot>
|
||||
|
||||
<FormDescription v-if="props.description && !error">
|
||||
{{ props.description }}
|
||||
</FormDescription>
|
||||
|
||||
<FormMessage v-if="props.description" />
|
||||
</template>
|
||||
|
|
|
|||
|
|
@ -3,30 +3,17 @@ import { cn } from "@/lib/utils";
|
|||
import { useId } from "radix-vue";
|
||||
import { type HTMLAttributes, provide } from "vue";
|
||||
import { FORM_ITEM_INJECTION_KEY } from "./injectionKeys";
|
||||
import { useFormField } from "./useFormField";
|
||||
|
||||
const props = defineProps<{
|
||||
class?: HTMLAttributes["class"];
|
||||
label?: string;
|
||||
description?: string;
|
||||
}>();
|
||||
|
||||
const { error } = useFormField();
|
||||
|
||||
const id = useId();
|
||||
provide(FORM_ITEM_INJECTION_KEY, id);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div :class="cn('space-y-2', props.class)">
|
||||
<FormLabel v-if="props.label">{{ props.label }}</FormLabel>
|
||||
|
||||
<slot />
|
||||
|
||||
<FormDescription v-if="props.description && !error">
|
||||
{{ props.description }}
|
||||
</FormDescription>
|
||||
|
||||
<FormMessage v-if="props.description" />
|
||||
</div>
|
||||
</template>
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user