Skip to content

fix[select]: fix placeholder error when inputting Chinese #7611

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions components/vc-select/Selector/SingleSelector.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import pickAttrs from '../../_util/pickAttrs';
import Input from './Input';
import type { InnerSelectorProps } from './interface';
import { Fragment, computed, defineComponent, shallowRef, watch } from 'vue';
import { Fragment, Ref, computed, defineComponent, shallowRef, watch } from 'vue';
import PropTypes from '../../_util/vue-types';
import type { VueNode } from '../../_util/type';
import useInjectLegacySelectContext from '../../vc-tree-select/LegacyContext';
Expand All @@ -10,6 +10,9 @@ interface SelectorProps extends InnerSelectorProps {
inputElement: VueNode;
activeValue: string;
optionLabelRender: Function;

// placeholder
compositionStatus: boolean;
}
const props = {
inputElement: PropTypes.any,
Expand All @@ -20,6 +23,7 @@ const props = {
searchValue: String,
inputRef: PropTypes.any,
placeholder: PropTypes.any,
compositionStatus: { type: Boolean, default: undefined },
disabled: { type: Boolean, default: undefined },
mode: String,
showSearch: { type: Boolean, default: undefined },
Expand Down Expand Up @@ -65,7 +69,9 @@ const SingleSelector = defineComponent<SelectorProps>({

// Not show text when closed expect combobox mode
const hasTextInput = computed(() =>
props.mode !== 'combobox' && !props.open && !props.showSearch ? false : !!inputValue.value,
props.mode !== 'combobox' && !props.open && !props.showSearch
? false
: !!inputValue.value || props.compositionStatus,
);

const title = computed(() => {
Expand Down
18 changes: 12 additions & 6 deletions components/vc-select/Selector/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import type { CustomTagProps, DisplayValueType, Mode, RenderNode } from '../Base
import { isValidateOpenKey } from '../utils/keyUtil';
import useLock from '../hooks/useLock';
import type { PropType } from 'vue';
import { defineComponent } from 'vue';
import { defineComponent, ref } from 'vue';
import createRef from '../../_util/createRef';
import PropTypes from '../../_util/vue-types';
import type { VueNode } from '../../_util/type';
Expand Down Expand Up @@ -124,7 +124,7 @@ const Selector = defineComponent<SelectorProps>({
} as any,
setup(props, { expose }) {
const inputRef = createRef();
let compositionStatus = false;
let compositionStatus = ref(false);

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

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

const triggerOnSearch = (value: string) => {
if (props.onSearch(value, true, compositionStatus) !== false) {
if (props.onSearch(value, true, compositionStatus.value) !== false) {
props.onToggleOpen(true);
}
};

const onInputCompositionStart = () => {
compositionStatus = true;
compositionStatus.value = true;
};

const onInputCompositionEnd = (e: InputEvent) => {
compositionStatus = false;
compositionStatus.value = false;
// Trigger search again to support `tokenSeparators` with typewriting
if (props.mode !== 'combobox') {
triggerOnSearch((e.target as HTMLInputElement).value);
Expand Down Expand Up @@ -251,6 +256,7 @@ const Selector = defineComponent<SelectorProps>({
onInputMouseDown: onInternalInputMouseDown,
onInputChange,
onInputPaste,
compositionStatus: compositionStatus.value,
onInputCompositionStart,
onInputCompositionEnd,
};
Expand Down
Loading