From f194efca968f9350e4132aacbd434f1e6a4ebb7f Mon Sep 17 00:00:00 2001 From: msidolphin Date: Fri, 11 Feb 2022 11:43:58 +0800 Subject: [PATCH] fix: [el-select-v2] avoid remove new option when reserve-keyword is true (#5912) --- packages/components/select-v2/src/useAllowCreate.ts | 9 ++++++++- packages/components/select-v2/src/useSelect.ts | 5 ++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/packages/components/select-v2/src/useAllowCreate.ts b/packages/components/select-v2/src/useAllowCreate.ts index bd5f466d566cd..1ec803821b8c1 100644 --- a/packages/components/select-v2/src/useAllowCreate.ts +++ b/packages/components/select-v2/src/useAllowCreate.ts @@ -58,7 +58,14 @@ export function useAllowCreate(props: ISelectProps, states) { } function removeNewOption(option: Option) { - if (!enableAllowCreateMode.value || !option || !option.created) { + if ( + !enableAllowCreateMode.value || + !option || + !option.created || + (option.created && + props.reserveKeyword && + states.inputValue === option.label) + ) { return } const idx = states.createdOptions.findIndex( diff --git a/packages/components/select-v2/src/useSelect.ts b/packages/components/select-v2/src/useSelect.ts index 8c2c18b8e9f0a..55b70bf4eda8c 100644 --- a/packages/components/select-v2/src/useSelect.ts +++ b/packages/components/select-v2/src/useSelect.ts @@ -591,7 +591,10 @@ const useSelect = (props: ExtractPropTypes, emit) => { const onKeyboardSelect = () => { if (!expanded.value) { return toggleMenu() - } else if (~states.hoveringIndex) { + } else if ( + ~states.hoveringIndex && + filteredOptions.value[states.hoveringIndex] + ) { onSelect( filteredOptions.value[states.hoveringIndex], states.hoveringIndex,