Skip to content

Commit

Permalink
Merge pull request arco-design#2657 from arco-design/enhance/select
Browse files Browse the repository at this point in the history
Enhance/select
  • Loading branch information
flsion authored Apr 26, 2024
2 parents 03f7cf7 + ad7492e commit df01991
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions components/Select/select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ import useMergeProps from '../_util/hooks/useMergeProps';
import { SelectOptionProps } from '../index';
import useId from '../_util/hooks/useId';

// 用户创建中的option的origin标识
const USER_CREATING_OPTION_ORIGIN = 'userCreatingOption';

const defaultProps: SelectProps = {
trigger: 'click',
bordered: true,
Expand Down Expand Up @@ -186,7 +189,11 @@ function Select(baseProps: SelectProps, ref) {
const isFirstValueOptionSelectable =
!isNoOptionSelected && optionInfoMap.get(firstValue)?._valid;

return isFirstValueOptionSelectable
// 是否第一个 option 是创建中选项
const isFirstCreatingOption =
optionInfoMap?.get(optionValueList[0])?._origin === USER_CREATING_OPTION_ORIGIN;

return isFirstValueOptionSelectable && !isFirstCreatingOption
? firstValue
: optionValueList[optionIndexListForArrowKey[0]];
}
Expand Down Expand Up @@ -306,7 +313,7 @@ function Select(baseProps: SelectProps, ref) {
.filter((v) => {
const option =
optionInfoMap.get(v) || refValueMap.current.find((item) => item.value === v)?.option;
return !option || option._origin === 'userCreatingOption';
return !option || option._origin === USER_CREATING_OPTION_ORIGIN;
})
.map((op) => userCreatedOptionFormatter(op as string));
// 将 value 中不存在的 Option 移除
Expand Down

0 comments on commit df01991

Please sign in to comment.