mirror of
https://github.com/ArthurDanjou/ui.git
synced 2026-01-14 12:14:41 +01:00
fix(FormField): block form field injection after use (#4150)
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { inject, computed, type InjectionKey, type Ref, type ComputedRef } from 'vue'
|
||||
import { inject, computed, type InjectionKey, type Ref, type ComputedRef, provide } from 'vue'
|
||||
import { type UseEventBusReturn, useDebounceFn } from '@vueuse/core'
|
||||
import type { FormFieldProps } from '../types'
|
||||
import type { FormEvent, FormInputEvents, FormFieldInjectedOptions, FormInjectedOptions } from '../types/form'
|
||||
@@ -15,7 +15,7 @@ type Props<T> = {
|
||||
|
||||
export const formOptionsInjectionKey: InjectionKey<ComputedRef<FormInjectedOptions>> = Symbol('nuxt-ui.form-options')
|
||||
export const formBusInjectionKey: InjectionKey<UseEventBusReturn<FormEvent<any>, string>> = Symbol('nuxt-ui.form-events')
|
||||
export const formFieldInjectionKey: InjectionKey<ComputedRef<FormFieldInjectedOptions<FormFieldProps>>> = Symbol('nuxt-ui.form-field')
|
||||
export const formFieldInjectionKey: InjectionKey<ComputedRef<FormFieldInjectedOptions<FormFieldProps>> | undefined> = Symbol('nuxt-ui.form-field')
|
||||
export const inputIdInjectionKey: InjectionKey<Ref<string | undefined>> = Symbol('nuxt-ui.input-id')
|
||||
export const formInputsInjectionKey: InjectionKey<Ref<Record<string, { id?: string, pattern?: RegExp }>>> = Symbol('nuxt-ui.form-inputs')
|
||||
export const formLoadingInjectionKey: InjectionKey<Readonly<Ref<boolean>>> = Symbol('nuxt-ui.form-loading')
|
||||
@@ -27,6 +27,9 @@ export function useFormField<T>(props?: Props<T>, opts?: { bind?: boolean, defer
|
||||
const formInputs = inject(formInputsInjectionKey, undefined)
|
||||
const inputId = inject(inputIdInjectionKey, undefined)
|
||||
|
||||
// Blocks the FormField injection to avoid duplicating events when nesting input components.
|
||||
provide(formFieldInjectionKey, undefined)
|
||||
|
||||
if (formField && inputId) {
|
||||
if (opts?.bind === false) {
|
||||
// Removes for="..." attribute on label for RadioGroup and alike.
|
||||
|
||||
Reference in New Issue
Block a user