fix: 修复中文输入法拼音阶段选择选项后显示空白的问题

pull/8394/head
chenjy29 2025-10-27 17:48:30 +08:00
parent 35c1ad9c80
commit 4c90f46f51
3 changed files with 65 additions and 9 deletions

View File

@ -281,6 +281,14 @@ export default defineComponent({
const selectorRef = shallowRef<RefSelectorProps>(null); const selectorRef = shallowRef<RefSelectorProps>(null);
const listRef = shallowRef<RefOptionListProps>(null); const listRef = shallowRef<RefOptionListProps>(null);
const blurRef = ref<boolean>(false); const blurRef = ref<boolean>(false);
const compositionStatus = ref<boolean>(false); // BaseSelect
const onCompositionStart = () => {
// compositionStatustrue
compositionStatus.value = true;
};
const onCompositionEnd = () => {
compositionStatus.value = false;
};
/** Used for component focused management */ /** Used for component focused management */
const [mockFocused, setMockFocused, cancelSetMockFocused] = useDelayReset(); const [mockFocused, setMockFocused, cancelSetMockFocused] = useDelayReset();
@ -765,6 +773,7 @@ export default defineComponent({
let clearNode: VueNode; let clearNode: VueNode;
const onClearMouseDown: MouseEventHandler = () => { const onClearMouseDown: MouseEventHandler = () => {
onClear?.(); onClear?.();
onCompositionEnd();
onDisplayValuesChange([], { onDisplayValuesChange([], {
type: 'clear', type: 'clear',
@ -866,6 +875,9 @@ export default defineComponent({
onSearchSubmit={onInternalSearchSubmit} onSearchSubmit={onInternalSearchSubmit}
onRemove={onSelectorRemove} onRemove={onSelectorRemove}
tokenWithEnter={tokenWithEnter.value} tokenWithEnter={tokenWithEnter.value}
compositionStatus={compositionStatus.value}
onCompositionStart={onCompositionStart}
onCompositionEnd={onCompositionEnd}
/> />
); );
}, },

View File

@ -44,6 +44,9 @@ const SingleSelector = defineComponent<SelectorProps>({
setup(props) { setup(props) {
const inputChanged = shallowRef(false); const inputChanged = shallowRef(false);
//
const hasInput = shallowRef(false);
const combobox = computed(() => props.mode === 'combobox'); const combobox = computed(() => props.mode === 'combobox');
const inputEditable = computed(() => combobox.value || props.showSearch); const inputEditable = computed(() => combobox.value || props.showSearch);
@ -65,13 +68,39 @@ const SingleSelector = defineComponent<SelectorProps>({
{ immediate: true }, { immediate: true },
); );
// Not show text when closed expect combobox mode //
const hasTextInput = computed(() => watch(
props.mode !== 'combobox' && !props.open && !props.showSearch () => props.open,
? false newOpen => {
: !!inputValue.value || props.compositionStatus, if (!newOpen) {
hasInput.value = false;
}
},
); );
// values
watch(
() => props.values,
() => {
if (props.values && props.values.length > 0) {
hasInput.value = false;
}
},
{ deep: true },
);
// Not show text when closed expect combobox mode
const hasTextInput = computed(() => {
// true
if (!hasInput.value) {
return false;
}
return props.mode !== 'combobox' && !props.open && !props.showSearch
? false
: !!inputValue.value || props.compositionStatus;
});
const title = computed(() => { const title = computed(() => {
const item = props.values[0]; const item = props.values[0];
return item && (typeof item.label === 'string' || typeof item.label === 'number') return item && (typeof item.label === 'string' || typeof item.label === 'number')
@ -92,6 +121,10 @@ const SingleSelector = defineComponent<SelectorProps>({
}; };
const handleInput = (e: Event) => { const handleInput = (e: Event) => {
const composing = (e.target as any).composing; const composing = (e.target as any).composing;
// true
hasInput.value = true;
if (!composing) { if (!composing) {
inputChanged.value = true; inputChanged.value = true;
props.onInputChange(e); props.onInputChange(e);
@ -142,6 +175,7 @@ const SingleSelector = defineComponent<SelectorProps>({
} }
return ( return (
<> <>
{hasTextInput.value ? '输入中' : '输入完成'}
<span class={`${prefixCls}-selection-search`}> <span class={`${prefixCls}-selection-search`}>
<Input <Input
inputRef={inputRef} inputRef={inputRef}

View File

@ -15,7 +15,7 @@ import type { CustomTagProps, DisplayValueType, Mode, RenderNode } from '../Base
import { isValidateOpenKey } from '../utils/keyUtil'; import { isValidateOpenKey } from '../utils/keyUtil';
import useLock from '../hooks/useLock'; import useLock from '../hooks/useLock';
import type { PropType } from 'vue'; import type { PropType } from 'vue';
import { defineComponent, ref } from 'vue'; import { defineComponent, ref, computed } from 'vue';
import createRef from '../../_util/createRef'; import createRef from '../../_util/createRef';
import PropTypes from '../../_util/vue-types'; import PropTypes from '../../_util/vue-types';
import type { VueNode } from '../../_util/type'; import type { VueNode } from '../../_util/type';
@ -60,6 +60,9 @@ export interface SelectorProps {
onSearchSubmit: (searchText: string) => void; onSearchSubmit: (searchText: string) => void;
onRemove: (value: DisplayValueType) => void; onRemove: (value: DisplayValueType) => void;
onInputKeyDown?: (e: KeyboardEvent) => void; onInputKeyDown?: (e: KeyboardEvent) => void;
compositionStatus?: boolean;
onCompositionStart?: () => void;
onCompositionEnd?: () => void;
/** /**
* @private get real dom for trigger align. * @private get real dom for trigger align.
@ -115,6 +118,9 @@ const Selector = defineComponent<SelectorProps>({
onSearchSubmit: Function, onSearchSubmit: Function,
onRemove: Function, onRemove: Function,
onInputKeyDown: { type: Function as PropType<EventHandler> }, onInputKeyDown: { type: Function as PropType<EventHandler> },
compositionStatus: { type: Boolean, default: false },
onCompositionStart: { type: Function as PropType<() => void> },
onCompositionEnd: { type: Function as PropType<() => void> },
/** /**
* @private get real dom for trigger align. * @private get real dom for trigger align.
@ -124,7 +130,7 @@ const Selector = defineComponent<SelectorProps>({
} as any, } as any,
setup(props, { expose }) { setup(props, { expose }) {
const inputRef = createRef(); const inputRef = createRef();
const compositionStatus = ref(false); const compositionStatus = computed(() => props.compositionStatus || false);
// ====================== Input ====================== // ====================== Input ======================
const [getInputMouseDown, setInputMouseDown] = useLock(0); const [getInputMouseDown, setInputMouseDown] = useLock(0);
@ -174,11 +180,13 @@ const Selector = defineComponent<SelectorProps>({
}; };
const onInputCompositionStart = () => { const onInputCompositionStart = () => {
compositionStatus.value = true; // compositionStatus.value = true;
props.onCompositionStart();
}; };
const onInputCompositionEnd = (e: InputEvent) => { const onInputCompositionEnd = (e: InputEvent) => {
compositionStatus.value = false; // compositionStatus.value = false;
props.onCompositionEnd();
// Trigger search again to support `tokenSeparators` with typewriting // Trigger search again to support `tokenSeparators` with typewriting
if (props.mode !== 'combobox') { if (props.mode !== 'combobox') {
triggerOnSearch((e.target as HTMLInputElement).value); triggerOnSearch((e.target as HTMLInputElement).value);
@ -244,6 +252,8 @@ const Selector = defineComponent<SelectorProps>({
inputRef.current.focus(); inputRef.current.focus();
}, },
blur: () => { blur: () => {
console.log('onBlurrrrrrrr1111111');
props.onCompositionEnd();
inputRef.current.blur(); inputRef.current.blur();
}, },
}); });