From 4c4d3033636f85e69c368ae3eba40bcb951e332e Mon Sep 17 00:00:00 2001 From: chenjiahan Date: Sun, 10 Jan 2021 13:28:38 +0800 Subject: [PATCH] feat(Field): add autocomplate prop #7877 --- src/field/README.md | 1 + src/field/README.zh-CN.md | 1 + src/field/index.js | 2 ++ src/field/test/index.spec.js | 11 +++++++++++ 4 files changed, 15 insertions(+) diff --git a/src/field/README.md b/src/field/README.md index 52fd4f4d7..c37e4d16a 100644 --- a/src/field/README.md +++ b/src/field/README.md @@ -265,6 +265,7 @@ Use `input-align` prop to align the input value. | right-icon | Right side icon name | _string_ | - | | icon-prefix `v2.5.3` | Icon className prefix | _string_ | `van-icon` | | rules `v2.5.0` | Form validation rules | _Rule[]_ | - | +| autocomplete `v3.0.3` | [autocomplete](https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/autocomplete) attribute of native input element | _string_ | - | ### Events diff --git a/src/field/README.zh-CN.md b/src/field/README.zh-CN.md index 2c7cae08d..bf60eee62 100644 --- a/src/field/README.zh-CN.md +++ b/src/field/README.zh-CN.md @@ -288,6 +288,7 @@ export default { | right-icon | 右侧[图标名称](#/zh-CN/icon)或图片链接 | _string_ | - | | icon-prefix `v2.5.3` | 图标类名前缀,同 Icon 组件的 [class-prefix 属性](#/zh-CN/icon#props) | _string_ | `van-icon` | | rules `v2.5.0` | 表单校验规则,详见 [Form 组件](#/zh-CN/form#rule-shu-ju-jie-gou) | _Rule[]_ | - | +| autocomplete `v3.0.3` | input 标签原生的[自动完成属性](https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/autocomplete) | _string_ | - | ### Events diff --git a/src/field/index.js b/src/field/index.js index 4fcaf9d95..f2cd47702 100644 --- a/src/field/index.js +++ b/src/field/index.js @@ -51,6 +51,7 @@ export default createComponent({ labelAlign: String, inputAlign: String, placeholder: String, + autocomplete: String, errorMessage: String, errorMessageAlign: String, showWordLimit: Boolean, @@ -417,6 +418,7 @@ export default createComponent({ disabled, readonly, placeholder: props.placeholder, + autocomplete: props.autocomplete, onBlur, onFocus, onInput, diff --git a/src/field/test/index.spec.js b/src/field/test/index.spec.js index 181f0ccc4..e707db704 100644 --- a/src/field/test/index.spec.js +++ b/src/field/test/index.spec.js @@ -419,3 +419,14 @@ test('should format value after mounted if initial modelValue is null', () => { expect(wrapper.find('input').element.value).toEqual(''); expect(wrapper.emitted('update:modelValue')[0][0]).toEqual(''); }); + +test('should allow to set autocomplete attribute', () => { + const wrapper = mount(Field, { + props: { + autocomplete: 'on', + }, + }); + expect(wrapper.find('input').element.getAttribute('autocomplete')).toEqual( + 'on' + ); +});