fix: [el-select-v2] avoid remove new option when reserve-keyword is true (#5912)

This commit is contained in:
msidolphin 2022-02-11 11:43:58 +08:00 committed by GitHub
parent 2ed6fc4cee
commit f194efca96
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 2 deletions

View File

@ -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(

View File

@ -591,7 +591,10 @@ const useSelect = (props: ExtractPropTypes<typeof SelectProps>, 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,