Files
element-plus/packages/components/form/src/hooks/use-form-common-props.ts
sea 2c29081621 fix(hooks): [use-focus-controller] form-disabled-status not trigger blur (#20891)
* fix(components): [input] form-disabled-status blur not validate

* fix: update hooks

Co-authored-by: xingyixiang <452282988@qq.com>

* test: add form disabled case

* fix: test import

* Update packages/hooks/use-focus-controller/index.ts

Co-authored-by: btea <2356281422@qq.com>

* refactor: import path

---------

Co-authored-by: xingyixiang <452282988@qq.com>
Co-authored-by: btea <2356281422@qq.com>
2025-06-04 10:44:53 +08:00

46 lines
1.4 KiB
TypeScript

import { computed, inject, ref, unref } from 'vue'
import { useGlobalSize } from '@element-plus/hooks/use-size'
import { useProp } from '@element-plus/hooks/use-prop'
import { formContextKey, formItemContextKey } from '../constants'
import type { ComponentSize } from '@element-plus/constants'
import type { MaybeRef } from '@vueuse/core'
export const useFormSize = (
fallback?: MaybeRef<ComponentSize | undefined>,
ignore: Partial<Record<'prop' | 'form' | 'formItem' | 'global', boolean>> = {}
) => {
const emptyRef = ref(undefined)
const size = ignore.prop ? emptyRef : useProp<ComponentSize>('size')
const globalConfig = ignore.global ? emptyRef : useGlobalSize()
const form = ignore.form
? { size: undefined }
: inject(formContextKey, undefined)
const formItem = ignore.formItem
? { size: undefined }
: inject(formItemContextKey, undefined)
return computed(
(): ComponentSize =>
size.value ||
unref(fallback) ||
formItem?.size ||
form?.size ||
globalConfig.value ||
''
)
}
export const useFormDisabled = (fallback?: MaybeRef<boolean | undefined>) => {
const disabled = useProp<boolean>('disabled')
const form = inject(formContextKey, undefined)
return computed(
() => disabled.value || unref(fallback) || form?.disabled || false
)
}
// These exports are used for preventing breaking changes
export const useSize = useFormSize
export const useDisabled = useFormDisabled