From 521748a5f82c79f90603198491d054937c943f44 Mon Sep 17 00:00:00 2001 From: neverland Date: Sat, 26 Nov 2022 20:17:51 +0800 Subject: [PATCH] fix(Field): keep selection position after updating value (#11308) --- packages/vant/src/field/Field.tsx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/vant/src/field/Field.tsx b/packages/vant/src/field/Field.tsx index 10aca6c6b..dfc34c445 100644 --- a/packages/vant/src/field/Field.tsx +++ b/packages/vant/src/field/Field.tsx @@ -303,7 +303,9 @@ export default defineComponent({ } if (inputRef.value && inputRef.value.value !== value) { + const { selectionStart, selectionEnd } = inputRef.value; inputRef.value.value = value; + inputRef.value.setSelectionRange(selectionStart, selectionEnd); } if (value !== props.modelValue) {