diff --git a/docs/en-US/component/input.md b/docs/en-US/component/input.md index 6305be354e..2607a48b26 100644 --- a/docs/en-US/component/input.md +++ b/docs/en-US/component/input.md @@ -121,7 +121,7 @@ input/length-limiting | ----------------------------- | -------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------- | ----------- | | type | type of input, see more in [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#Form_%3Cinput%3E_types) | ^[string]`'text' \| 'textarea' \| 'number' \| 'password' \| 'email' \| 'search' \| 'tel' \| 'url'` | text | | model-value / v-model | binding value | ^[string] / ^[number] | — | -| model-modifiers ^(2.11.5) | v-model modifiers, reference [Vue modifiers](https://vuejs.org/guide/essentials/forms.html#modifiers) | ^[object]`{ lazy?: boolean, number?: boolean, trim?: boolean }` | — | +| model-modifiers ^(2.11.5) | v-model modifiers, reference [Vue modifiers](https://vuejs.org/guide/essentials/forms.html#modifiers) | ^[object]`{ lazy?: true, number?: true, trim?: true }` | — | | maxlength | same as `maxlength` in native input | ^[string] / ^[number] | — | | minlength | same as `minlength` in native input | ^[string] / ^[number] | — | | show-word-limit | whether show word count, only works when `type` is 'text' or 'textarea' | ^[boolean] | false | diff --git a/packages/components/input/src/input.ts b/packages/components/input/src/input.ts index 21448e915f..3c83ab2052 100644 --- a/packages/components/input/src/input.ts +++ b/packages/components/input/src/input.ts @@ -10,16 +10,17 @@ import { useAriaProps, useSizeProp } from '@element-plus/hooks' import { CircleClose } from '@element-plus/icons-vue' import type { - ExtractPropTypes, + Component, ExtractPublicPropTypes, HTMLAttributes, StyleValue, } from 'vue' +import type { ComponentSize } from '@element-plus/constants' export type InputModelModifiers = { - lazy?: boolean - number?: boolean - trim?: boolean + lazy?: true + number?: true + trim?: true } export type InputAutoSize = { minRows?: number; maxRows?: number } | boolean // Some commonly used values for input type @@ -34,6 +35,141 @@ export type InputType = | 'url' | (string & NonNullable) +export interface InputProps { + /** + * @description native input id + */ + id?: string + /** + * @description input box size + */ + size?: ComponentSize + /** + * @description whether to disable + */ + disabled?: boolean + /** + * @description binding value + */ + modelValue?: string | number | null | undefined + /** + * @description v-model modifiers, reference [Vue modifiers](https://vuejs.org/guide/essentials/forms.html#modifiers) + */ + modelModifiers?: InputModelModifiers + /** + * @description same as `maxlength` in native input + */ + maxlength?: string | number + /** + * @description same as `minlength` in native input + */ + minlength?: string | number + /** + * @description type of input, see more in [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#Form_%3Cinput%3E_types) + */ + type?: InputType + /** + * @description control the resizability + */ + resize?: 'none' | 'both' | 'horizontal' | 'vertical' + /** + * @description whether textarea has an adaptive height + */ + autosize?: InputAutoSize + /** + * @description native input autocomplete + * - When the number of literal types in a union exceeds 315, the TS2590 error occurs. see: https://github.com/vuejs/core/issues/10514 + */ + autocomplete?: string // HTMLInputElement['autocomplete'] + /** + * @description format content + */ + formatter?: (value: string) => string + /** + * @description parse content + */ + parser?: (value: string) => string + /** + * @description placeholder + */ + placeholder?: string + /** + * @description native input form + */ + form?: string + /** + * @description native input readonly + */ + readonly?: boolean + /** + * @description whether to show clear button + */ + clearable?: boolean + /** + * @description custom clear icon component + */ + clearIcon?: string | Component + /** + * @description toggleable password input + */ + showPassword?: boolean + /** + * @description word count + */ + showWordLimit?: boolean + /** + * @description word count position, valid when `show-word-limit` is true + */ + wordLimitPosition?: 'inside' | 'outside' + /** + * @description suffix icon + */ + suffixIcon?: string | Component + /** + * @description prefix icon + */ + prefixIcon?: string | Component + /** + * @description container role, internal properties provided for use by the picker component + */ + containerRole?: string + /** + * @description input tabindex + */ + tabindex?: string | number + /** + * @description whether to trigger form validation + */ + validateEvent?: boolean + /** + * @description input or textarea element style + */ + inputStyle?: StyleValue + /** + * @description native input autofocus + */ + autofocus?: boolean + /** + * @description number of rows of textarea, only works when `type` is 'textarea' + */ + rows?: number + /** + * @description native `aria-label` attribute + */ + ariaLabel?: string + /** + * @description native input mode for virtual keyboards + */ + inputmode?: HTMLAttributes['inputmode'] + /** + * @description same as `name` in native input + */ + name?: string +} + +/** + * @deprecated Removed after 3.0.0, Use `InputProps` instead. + */ export const inputProps = buildProps({ /** * @description native input id @@ -227,7 +363,10 @@ export const inputProps = buildProps({ */ name: String, } as const) -export type InputProps = ExtractPropTypes + +/** + * @deprecated Removed after 3.0.0, Use `InputProps` instead. + */ export type InputPropsPublic = ExtractPublicPropTypes export const inputEmits = { diff --git a/packages/components/input/src/input.vue b/packages/components/input/src/input.vue index 4e6ca936b7..9e2d51b4e8 100644 --- a/packages/components/input/src/input.vue +++ b/packages/components/input/src/input.vue @@ -163,6 +163,7 @@