From bf2d6711423299e3ea673bb8f4e59a37b63d9b2c Mon Sep 17 00:00:00 2001 From: btea <2356281422@qq.com> Date: Mon, 13 Jun 2022 14:49:18 +0800 Subject: [PATCH] refactor(components): [input] fix ts error (#8200) --- packages/components/input/src/input.vue | 11 +++++++---- packages/tokens/form.ts | 3 ++- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/packages/components/input/src/input.vue b/packages/components/input/src/input.vue index 5c50946af8..4a2117df4a 100644 --- a/packages/components/input/src/input.vue +++ b/packages/components/input/src/input.vue @@ -80,7 +80,7 @@ @@ -174,6 +174,7 @@ import { View as IconView, } from '@element-plus/icons-vue' import { + NOOP, ValidateComponentsMap, debugWarn, isKorean, @@ -210,8 +211,8 @@ const instance = getCurrentInstance()! const rawAttrs = useRawAttrs() const slots = useSlots() -const containerAttrs = computed>(() => { - const comboBoxAttrs = {} +const containerAttrs = computed(() => { + const comboBoxAttrs: Record = {} if (props.containerRole === 'combobox') { comboBoxAttrs['aria-haspopup'] = rawAttrs['aria-haspopup'] comboBoxAttrs['aria-owns'] = rawAttrs['aria-owns'] @@ -248,7 +249,9 @@ const _ref = computed(() => input.value || textarea.value) const needStatusIcon = computed(() => form?.statusIcon ?? false) const validateState = computed(() => formItem?.validateState || '') -const validateIcon = computed(() => ValidateComponentsMap[validateState.value]) +const validateIcon = computed( + () => validateState.value && ValidateComponentsMap[validateState.value] +) const passwordIcon = computed(() => passwordVisible.value ? IconView : IconHide ) diff --git a/packages/tokens/form.ts b/packages/tokens/form.ts index 4404b558c2..d6357a6440 100644 --- a/packages/tokens/form.ts +++ b/packages/tokens/form.ts @@ -9,6 +9,7 @@ import type { FormEmits, FormItemProp, FormItemProps, + FormItemValidateState, FormLabelWidthContext, FormProps, } from '@element-plus/components/form' @@ -47,7 +48,7 @@ export type FormContext = FormProps & export interface FormItemContext extends FormItemProps { $el: HTMLDivElement | undefined size: ComponentSize - validateState: string + validateState: FormItemValidateState isGroup: boolean labelId: string inputIds: string[]