Skip to content

Commit

Permalink
fix: [el-select-v2] avoid remove new option when reserve-keyword is t…
Browse files Browse the repository at this point in the history
  • Loading branch information
msidolphin authored Feb 11, 2022
1 parent 2ed6fc4 commit f194efc
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
9 changes: 8 additions & 1 deletion packages/components/select-v2/src/useAllowCreate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
5 changes: 4 additions & 1 deletion packages/components/select-v2/src/useSelect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit f194efc

Please sign in to comment.