From 96ef2557c24b1afbe335b6e3c4f0a8778645788f Mon Sep 17 00:00:00 2001 From: neverland Date: Thu, 21 May 2020 19:15:50 +0800 Subject: [PATCH] feat(Form): scrollToField can scroll to bottom (#6335) --- src/form/README.md | 12 ++++++------ src/form/README.zh-CN.md | 2 +- src/form/index.js | 4 ++-- types/form.d.ts | 2 +- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/form/README.md b/src/form/README.md index 062f34e4e..1fe20070c 100644 --- a/src/form/README.md +++ b/src/form/README.md @@ -457,12 +457,12 @@ export default { Use [ref](https://vuejs.org/v2/api/#ref) to get Form instance and call instance methods -| Name | Description | Attribute | Return value | -| ---------------------- | ---------------- | --------------- | ------------ | -| submit | Submit form | - | - | -| validate | Validate form | _name?: string_ | _Promise_ | -| resetValidation | Reset validation | _name?: string_ | - | -| scrollToField `v2.5.2` | Scroll to field | _name: string_ | - | +| Name | Description | Attribute | Return value | +| --- | --- | --- | --- | +| submit | Submit form | - | - | +| validate | Validate form | _name?: string_ | _Promise_ | +| resetValidation | Reset validation | _name?: string_ | - | +| scrollToField `v2.8.2` | Scroll to field | _name: string, alignToTop: boolean_ | - | ### Slots diff --git a/src/form/README.zh-CN.md b/src/form/README.zh-CN.md index 00ad6e42f..e6ce3f0af 100644 --- a/src/form/README.zh-CN.md +++ b/src/form/README.zh-CN.md @@ -501,7 +501,7 @@ export default { | submit | 提交表单,与点击提交按钮的效果等价 | - | - | | validate | 验证表单,支持传入`name`来验证单个表单项 | _name?: string_ | _Promise_ | | resetValidation | 重置表单项的验证提示,支持传入`name`来重置单个表单项 | _name?: string_ | - | -| scrollToField `v2.5.2` | 滚动到对应表单项的位置 | _name: string_ | - | +| scrollToField `v2.8.2` | 滚动到对应表单项的位置,默认滚动到顶部,第二个参数传 false 可滚动至底部 | _name: string, alignToTop: boolean_ | - | ### Slots diff --git a/src/form/index.js b/src/form/index.js index ba5bf22be..c3254a53d 100644 --- a/src/form/index.js +++ b/src/form/index.js @@ -119,10 +119,10 @@ export default createComponent({ }, // @exposed-api - scrollToField(name) { + scrollToField(name, options) { this.fields.forEach((item) => { if (item.name === name) { - item.$el.scrollIntoView(); + item.$el.scrollIntoView(options); } }); }, diff --git a/types/form.d.ts b/types/form.d.ts index df0742623..3f11ee7fd 100644 --- a/types/form.d.ts +++ b/types/form.d.ts @@ -7,5 +7,5 @@ export class Form extends VanComponent { resetValidation(name?: string): void; - scrollToField(name: string): void; + scrollToField(name: string, options?: boolean | ScrollIntoViewOptions): void; }