From dbb3d1337d9361b272ee2a5317884596eedd1b0e Mon Sep 17 00:00:00 2001 From: DCloud_LXH <283700113@qq.com> Date: Wed, 7 Jul 2021 18:38:18 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20input=20=E6=B7=BB=E5=8A=A0=20tel=20?= =?UTF-8?q?=E5=B1=9E=E6=80=A7=E3=80=81=E6=B7=BB=E5=8A=A0=20text-content-ty?= =?UTF-8?q?pe=20=E5=B1=9E=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/components/input/index.tsx | 24 ++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/packages/uni-components/src/components/input/index.tsx b/packages/uni-components/src/components/input/index.tsx index d77b55954..46f540a41 100644 --- a/packages/uni-components/src/components/input/index.tsx +++ b/packages/uni-components/src/components/input/index.tsx @@ -1,4 +1,4 @@ -import { extend } from '@vue/shared' +import { extend, hyphenate } from '@vue/shared' import { Ref, ref, computed } from 'vue' import { defineBuiltInComponent } from '../../helpers/component' import { @@ -12,6 +12,10 @@ const props = /*#__PURE__*/ extend({}, fieldProps, { type: String, default: 'input-placeholder', }, + textContentType: { + type: String, + default: '', + }, }) export default /*#__PURE__*/ defineBuiltInComponent({ @@ -19,7 +23,8 @@ export default /*#__PURE__*/ defineBuiltInComponent({ props, emits: ['confirm', ...fieldEmit], setup(props, { emit }) { - const INPUT_TYPES = ['text', 'number', 'idcard', 'digit', 'password'] + const INPUT_TYPES = ['text', 'number', 'idcard', 'digit', 'password', 'tel'] + const AUTOCOMPLETES = ['off', 'one-time-code'] const type = computed(() => { let type = '' switch (props.type) { @@ -41,6 +46,19 @@ export default /*#__PURE__*/ defineBuiltInComponent({ } return props.password ? 'password' : type }) + const autocomplete = computed(() => { + const camelizeIndex = AUTOCOMPLETES.indexOf(props.textContentType) + const kebabCaseIndex = AUTOCOMPLETES.indexOf( + hyphenate(props.textContentType) + ) + const index = + camelizeIndex !== -1 + ? camelizeIndex + : kebabCaseIndex !== -1 + ? kebabCaseIndex + : 0 + return AUTOCOMPLETES[index] + }) let cache = ref('') let resetCache: (() => void) | null @@ -132,7 +150,7 @@ export default /*#__PURE__*/ defineBuiltInComponent({ enterkeyhint={props.confirmType} pattern={props.type === 'number' ? '[0-9]*' : undefined} class="uni-input-input" - autocomplete="off" + autocomplete={autocomplete.value} onKeyup={onKeyUpEnter} /> ) -- GitLab