fix(Field): textarea scroll to top after resizing (#9207)

This commit is contained in:
neverland 2021-08-08 17:42:51 +08:00 committed by GitHub
parent 824fbb8c6f
commit 405170f5e6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -2,6 +2,7 @@
import { resetScroll } from '../utils/dom/reset-scroll'; import { resetScroll } from '../utils/dom/reset-scroll';
import { formatNumber } from '../utils/format/number'; import { formatNumber } from '../utils/format/number';
import { preventDefault } from '../utils/dom/event'; import { preventDefault } from '../utils/dom/event';
import { getRootScrollTop, setRootScrollTop } from '../utils/dom/scroll';
import { import {
isDef, isDef,
addUnit, addUnit,
@ -347,7 +348,7 @@ export default createComponent({
this.focused = true; this.focused = true;
this.$emit('focus', event); this.$emit('focus', event);
// readonly not work in lagacy mobile safari // readonly not work in legacy mobile safari
/* istanbul ignore if */ /* istanbul ignore if */
const readonly = this.getProp('readonly'); const readonly = this.getProp('readonly');
if (readonly) { if (readonly) {
@ -409,6 +410,7 @@ export default createComponent({
return; return;
} }
const scrollTop = getRootScrollTop();
input.style.height = 'auto'; input.style.height = 'auto';
let height = input.scrollHeight; let height = input.scrollHeight;
@ -424,6 +426,8 @@ export default createComponent({
if (height) { if (height) {
input.style.height = height + 'px'; input.style.height = height + 'px';
// https://github.com/youzan/vant/issues/9178
setRootScrollTop(scrollTop);
} }
}, },
@ -475,8 +479,8 @@ export default createComponent({
let inputType = type; let inputType = type;
let inputMode; let inputMode;
// type="number" is weired in iOS, and can't prevent dot in Android // type="number" is weird in iOS, and can't prevent dot in Android
// so use inputmode to set keyboard in mordern browers // so use inputmode to set keyboard in modern browsers
if (type === 'number') { if (type === 'number') {
inputType = 'text'; inputType = 'text';
inputMode = 'decimal'; inputMode = 'decimal';