Skip to content

Commit 66eb020

Browse files
committed
fix: input textarea cursor pos error
1 parent 31c8339 commit 66eb020

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

components/input/Input.tsx

+10-7
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ export function resolveOnChange(
3737
return;
3838
}
3939
const event: any = e;
40-
const originalInputValue = target.value;
4140

4241
if (e.type === 'click') {
4342
Object.defineProperty(event, 'target', {
@@ -48,13 +47,13 @@ export function resolveOnChange(
4847
});
4948
// click clear icon
5049
//event = Object.create(e);
51-
event.target = target;
52-
event.currentTarget = target;
50+
const currentTarget = target.cloneNode(true);
51+
52+
event.target = currentTarget;
53+
event.currentTarget = currentTarget;
5354
// change target ref value cause e.target.value should be '' when clear input
54-
target.value = '';
55+
(currentTarget as any).value = '';
5556
onChange(event);
56-
// reset target ref value
57-
target.value = originalInputValue;
5857
return;
5958
}
6059
// Trigger by composition event, this means we need force change the input value
@@ -227,7 +226,11 @@ export default defineComponent({
227226
if (props.value === undefined) {
228227
stateValue.value = value;
229228
} else {
230-
instance.update();
229+
nextTick(() => {
230+
if (inputRef.value.value !== stateValue.value) {
231+
instance.update();
232+
}
233+
});
231234
}
232235
nextTick(() => {
233236
callback && callback();

components/input/TextArea.tsx

+7-2
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ export default defineComponent({
3131
const formItemContext = useInjectFormItemContext();
3232
const stateValue = ref(props.value === undefined ? props.defaultValue : props.value);
3333
const resizableTextArea = ref();
34+
const mergedValue = ref('');
3435
const { prefixCls, size, direction } = useConfigInject('input', props);
3536
const showCount = computed(() => {
3637
return (props.showCount as any) === '' || props.showCount || false;
@@ -63,7 +64,11 @@ export default defineComponent({
6364
if (props.value === undefined) {
6465
stateValue.value = value;
6566
} else {
66-
resizableTextArea.value?.instance.update?.();
67+
nextTick(() => {
68+
if (resizableTextArea.value.textArea.value !== mergedValue.value) {
69+
resizableTextArea.value?.instance.update?.();
70+
}
71+
});
6772
}
6873
nextTick(() => {
6974
callback && callback();
@@ -152,7 +157,7 @@ export default defineComponent({
152157
blur,
153158
resizableTextArea,
154159
});
155-
const mergedValue = ref('');
160+
156161
watchEffect(() => {
157162
let val = fixControlledValue(stateValue.value) as string;
158163
if (

0 commit comments

Comments
 (0)