Skip to content

Commit 6e2c5a6

Browse files
fix[select]: fix placeholder error when inputting Chinese (#7611)
* fix[select]: fix placeholder error when inputting Chinese fix(selector): fix placeholder error when inputting Chinese perf: optimize types * Update SingleSelector.tsx * Update index.tsx --------- Co-authored-by: tangjinzhou <[email protected]>
1 parent 307148e commit 6e2c5a6

File tree

2 files changed

+20
-8
lines changed

2 files changed

+20
-8
lines changed

Diff for: components/vc-select/Selector/SingleSelector.tsx

+8-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import pickAttrs from '../../_util/pickAttrs';
22
import Input from './Input';
33
import type { InnerSelectorProps } from './interface';
4-
import { Fragment, computed, defineComponent, shallowRef, watch } from 'vue';
4+
import { Fragment, Ref, computed, defineComponent, shallowRef, watch } from 'vue';
55
import PropTypes from '../../_util/vue-types';
66
import type { VueNode } from '../../_util/type';
77
import useInjectLegacySelectContext from '../../vc-tree-select/LegacyContext';
@@ -10,6 +10,9 @@ interface SelectorProps extends InnerSelectorProps {
1010
inputElement: VueNode;
1111
activeValue: string;
1212
optionLabelRender: Function;
13+
14+
// placeholder
15+
compositionStatus: boolean;
1316
}
1417
const props = {
1518
inputElement: PropTypes.any,
@@ -20,6 +23,7 @@ const props = {
2023
searchValue: String,
2124
inputRef: PropTypes.any,
2225
placeholder: PropTypes.any,
26+
compositionStatus: { type: Boolean, default: undefined },
2327
disabled: { type: Boolean, default: undefined },
2428
mode: String,
2529
showSearch: { type: Boolean, default: undefined },
@@ -65,7 +69,9 @@ const SingleSelector = defineComponent<SelectorProps>({
6569

6670
// Not show text when closed expect combobox mode
6771
const hasTextInput = computed(() =>
68-
props.mode !== 'combobox' && !props.open && !props.showSearch ? false : !!inputValue.value,
72+
props.mode !== 'combobox' && !props.open && !props.showSearch
73+
? false
74+
: !!inputValue.value || props.compositionStatus,
6975
);
7076

7177
const title = computed(() => {

Diff for: components/vc-select/Selector/index.tsx

+12-6
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import type { CustomTagProps, DisplayValueType, Mode, RenderNode } from '../Base
1515
import { isValidateOpenKey } from '../utils/keyUtil';
1616
import useLock from '../hooks/useLock';
1717
import type { PropType } from 'vue';
18-
import { defineComponent } from 'vue';
18+
import { defineComponent, ref } from 'vue';
1919
import createRef from '../../_util/createRef';
2020
import PropTypes from '../../_util/vue-types';
2121
import type { VueNode } from '../../_util/type';
@@ -124,7 +124,7 @@ const Selector = defineComponent<SelectorProps>({
124124
} as any,
125125
setup(props, { expose }) {
126126
const inputRef = createRef();
127-
let compositionStatus = false;
127+
let compositionStatus = ref(false);
128128

129129
// ====================== Input ======================
130130
const [getInputMouseDown, setInputMouseDown] = useLock(0);
@@ -140,7 +140,12 @@ const Selector = defineComponent<SelectorProps>({
140140
props.onInputKeyDown(event);
141141
}
142142

143-
if (which === KeyCode.ENTER && props.mode === 'tags' && !compositionStatus && !props.open) {
143+
if (
144+
which === KeyCode.ENTER &&
145+
props.mode === 'tags' &&
146+
!compositionStatus.value &&
147+
!props.open
148+
) {
144149
// When menu isn't open, OptionList won't trigger a value change
145150
// So when enter is pressed, the tag's input value should be emitted here to let selector know
146151
props.onSearchSubmit((event.target as HTMLInputElement).value);
@@ -163,17 +168,17 @@ const Selector = defineComponent<SelectorProps>({
163168
let pastedText = null;
164169

165170
const triggerOnSearch = (value: string) => {
166-
if (props.onSearch(value, true, compositionStatus) !== false) {
171+
if (props.onSearch(value, true, compositionStatus.value) !== false) {
167172
props.onToggleOpen(true);
168173
}
169174
};
170175

171176
const onInputCompositionStart = () => {
172-
compositionStatus = true;
177+
compositionStatus.value = true;
173178
};
174179

175180
const onInputCompositionEnd = (e: InputEvent) => {
176-
compositionStatus = false;
181+
compositionStatus.value = false;
177182
// Trigger search again to support `tokenSeparators` with typewriting
178183
if (props.mode !== 'combobox') {
179184
triggerOnSearch((e.target as HTMLInputElement).value);
@@ -251,6 +256,7 @@ const Selector = defineComponent<SelectorProps>({
251256
onInputMouseDown: onInternalInputMouseDown,
252257
onInputChange,
253258
onInputPaste,
259+
compositionStatus: compositionStatus.value,
254260
onInputCompositionStart,
255261
onInputCompositionEnd,
256262
};

0 commit comments

Comments
 (0)