diff --git a/packages/sku/components/SkuMessages.js b/packages/sku/components/SkuMessages.js index 89aac5dca..1cc450e1a 100644 --- a/packages/sku/components/SkuMessages.js +++ b/packages/sku/components/SkuMessages.js @@ -1,4 +1,4 @@ -import { use } from '../../utils'; +import { use, isIOS } from '../../utils'; import Cell from '../../cell'; import CellGroup from '../../cell-group'; import Field from '../../field'; @@ -118,6 +118,14 @@ export default sfc({ } } } + }, + handleBlur() { + // https://developers.weixin.qq.com/community/develop/doc/00044ae90742f8c82fb78fcae56800 + // 修复ios12键盘弹起后点击错位的问题 + /* istanbul ignore next */ + if (isIOS()) { + window.scrollTo(0, 0); + } } }, @@ -147,6 +155,7 @@ export default sfc({ required={String(message.required) === '1'} placeholder={this.getPlaceholder(message)} type={this.getType(message)} + onBlur={this.handleBlur} /> )))} diff --git a/packages/utils/index.ts b/packages/utils/index.ts index 2425ac177..4f8b3a78a 100644 --- a/packages/utils/index.ts +++ b/packages/utils/index.ts @@ -36,6 +36,11 @@ export function isAndroid(): boolean { return isServer ? false : /android/.test(navigator.userAgent.toLowerCase()); } +export function isIOS(): boolean { + /* istanbul ignore next */ + return isServer ? false : /ios|iphone|ipad|ipod/.test(navigator.userAgent.toLowerCase()); +} + export function range(num: number, min: number, max: number): number { return Math.min(Math.max(num, min), max); }