Skip to content

Commit 303797d

Browse files
committed
fix(MultipleSelector): fix inconsistency between targetValue and inputValue
1 parent aa211fd commit 303797d

File tree

1 file changed

+6
-17
lines changed

1 file changed

+6
-17
lines changed

components/vc-select/Selector/MultipleSelector.tsx

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import TransBtn from '../TransBtn';
22
import type { InnerSelectorProps } from './interface';
33
import Input from './Input';
44
import type { Ref, PropType } from 'vue';
5-
import { ref, watchEffect, computed, defineComponent, onMounted, shallowRef, watch } from 'vue';
5+
import { computed, defineComponent, onMounted, shallowRef, watch } from 'vue';
66
import classNames from '../../_util/classNames';
77
import pickAttrs from '../../_util/pickAttrs';
88
import PropTypes from '../../_util/vue-types';
@@ -93,14 +93,10 @@ const SelectSelector = defineComponent<SelectorProps>({
9393
() =>
9494
props.mode === 'tags' || ((props.showSearch && (props.open || focused.value)) as boolean),
9595
);
96-
const targetValue = ref('');
97-
watchEffect(() => {
98-
targetValue.value = inputValue.value;
99-
});
10096
// We measure width and set to the input immediately
10197
onMounted(() => {
10298
watch(
103-
targetValue,
99+
inputValue,
104100
() => {
105101
inputWidth.value = measureRef.value.scrollWidth;
106102
},
@@ -207,14 +203,6 @@ const SelectSelector = defineComponent<SelectorProps>({
207203
return defaultRenderSelector(content, content, false);
208204
}
209205

210-
const handleInput = (e: Event) => {
211-
const composing = (e.target as any).composing;
212-
targetValue.value = (e.target as any).value;
213-
if (!composing) {
214-
props.onInputChange(e);
215-
}
216-
};
217-
218206
return () => {
219207
const {
220208
id,
@@ -229,6 +217,7 @@ const SelectSelector = defineComponent<SelectorProps>({
229217
activeDescendantId,
230218
tabindex,
231219
compositionStatus,
220+
onInputChange,
232221
onInputPaste,
233222
onInputKeyDown,
234223
onInputMouseDown,
@@ -253,10 +242,10 @@ const SelectSelector = defineComponent<SelectorProps>({
253242
autocomplete={autocomplete}
254243
editable={inputEditable.value}
255244
activeDescendantId={activeDescendantId}
256-
value={targetValue.value}
245+
value={inputValue.value}
257246
onKeydown={onInputKeyDown}
258247
onMousedown={onInputMouseDown}
259-
onChange={handleInput}
248+
onChange={onInputChange}
260249
onPaste={onInputPaste}
261250
onCompositionstart={onInputCompositionStart}
262251
onCompositionend={onInputCompositionEnd}
@@ -268,7 +257,7 @@ const SelectSelector = defineComponent<SelectorProps>({
268257

269258
{/* Measure Node */}
270259
<span ref={measureRef} class={`${selectionPrefixCls.value}-search-mirror`} aria-hidden>
271-
{targetValue.value}&nbsp;
260+
{inputValue.value}&nbsp;
272261
</span>
273262
</div>
274263
);

0 commit comments

Comments
 (0)