From 7adfca61959d1525285ab48b385f5c9971ffc432 Mon Sep 17 00:00:00 2001 From: neverland Date: Sat, 25 Sep 2021 15:20:16 +0800 Subject: [PATCH] feat(Search): add name prop (#9563) --- packages/vant/src/field/Field.tsx | 2 +- packages/vant/src/field/README.md | 6 +++--- packages/vant/src/search/README.md | 2 ++ packages/vant/src/search/README.zh-CN.md | 2 ++ packages/vant/src/search/test/index.spec.ts | 9 +++++++++ 5 files changed, 17 insertions(+), 4 deletions(-) diff --git a/packages/vant/src/field/Field.tsx b/packages/vant/src/field/Field.tsx index c1cdb31e5..1c1fd2a54 100644 --- a/packages/vant/src/field/Field.tsx +++ b/packages/vant/src/field/Field.tsx @@ -61,6 +61,7 @@ const [name, bem] = createNamespace('field'); // provide to Search component to inherit export const fieldSharedProps = { id: String, + name: String, formatter: Function as PropType<(value: string) => string>, leftIcon: String, rightIcon: String, @@ -103,7 +104,6 @@ export const fieldSharedProps = { const props = extend({}, cellProps, fieldSharedProps, { rows: [Number, String], - name: String, rules: Array as PropType, autosize: [Boolean, Object] as PropType, labelWidth: [Number, String], diff --git a/packages/vant/src/field/README.md b/packages/vant/src/field/README.md index 4e9de3a7a..a042f7ccb 100644 --- a/packages/vant/src/field/README.md +++ b/packages/vant/src/field/README.md @@ -247,9 +247,9 @@ Use `input-align` prop to align the input value. | Attribute | Description | Type | Default | | --- | --- | --- | --- | -| v-model | Field value | _number \| string_ | - | -| label | Field label | _string_ | - | -| name | Field name | _string_ | - | +| v-model | Input value | _number \| string_ | - | +| label | Left side label | _string_ | - | +| name | As the identifier when submitting the form | _string_ | - | | id `v3.2.2` | Input id, the for attribute of the label also will be set | _string_ | - | | type | Input type, can be set to `tel` `digit`
`number` `textarea` `password` | _string_ | `text` | | size | Size,can be set to `large` | _string_ | - | diff --git a/packages/vant/src/search/README.md b/packages/vant/src/search/README.md index c1fe80ad1..257ee5217 100644 --- a/packages/vant/src/search/README.md +++ b/packages/vant/src/search/README.md @@ -118,7 +118,9 @@ Use `action` slot to custom right button, `cancel` event will no longer be Emitt | Attribute | Description | Type | Default | | --- | --- | --- | --- | +| v-model | Input value | _number \| string_ | - | | label | Left side label | _string_ | - | +| name `v3.2.3` | As the identifier when submitting the form | _string_ | - | | shape | Shape of field, can be set to `round` | _string_ | `square` | | id `v3.2.2` | Input id, the for attribute of the label also will be set | _string_ | - | | background | Background color of field | _string_ | `#f2f2f2` | diff --git a/packages/vant/src/search/README.zh-CN.md b/packages/vant/src/search/README.zh-CN.md index 947ee8a6d..1289ffc07 100644 --- a/packages/vant/src/search/README.zh-CN.md +++ b/packages/vant/src/search/README.zh-CN.md @@ -130,7 +130,9 @@ export default { | 参数 | 说明 | 类型 | 默认值 | | --- | --- | --- | --- | +| v-model | 当前输入的值 | _number \| string_ | - | | label | 搜索框左侧文本 | _string_ | - | +| name `v3.2.3` | 名称,作为提交表单时的标识符 | _string_ | - | | shape | 搜索框形状,可选值为 `round` | _string_ | `square` | | id `v3.2.2` | 搜索框 id,同时会设置 label 的 for 属性 | _string_ | - | | background | 搜索框外部背景色 | _string_ | `#f2f2f2` | diff --git a/packages/vant/src/search/test/index.spec.ts b/packages/vant/src/search/test/index.spec.ts index 436a35b41..825a33695 100644 --- a/packages/vant/src/search/test/index.spec.ts +++ b/packages/vant/src/search/test/index.spec.ts @@ -161,3 +161,12 @@ test('should allow to set autocomplete attribute', () => { 'on' ); }); + +test('should render input name when using name prop', () => { + const wrapper = mount(Search, { + props: { + name: 'foo', + }, + }); + expect(wrapper.find('input').element.getAttribute('name')).toEqual('foo'); +});