Skip to content

Commit

Permalink
fix: fix
Browse files Browse the repository at this point in the history
  • Loading branch information
li-jia-nan committed Dec 28, 2023
1 parent e265175 commit ed199a5
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions src/OptionList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ const OptionList: React.ForwardRefRenderFunction<RefOptionListProps, {}> = (_, r
// =========================== List ===========================
const listRef = React.useRef<ListRef>(null);

const shouldDisabled = React.useMemo<boolean>(
const overMaxCount = React.useMemo<boolean>(
() => multiple && typeof maxCount !== 'undefined' && rawValues.size >= maxCount,
[multiple, maxCount, rawValues.size],
);
Expand All @@ -95,7 +95,7 @@ const OptionList: React.ForwardRefRenderFunction<RefOptionListProps, {}> = (_, r

const { group, data } = memoFlattenOptions[current] || {};

if (!group && !data?.disabled && !shouldDisabled) {
if (!group && !data?.disabled && !overMaxCount) {
return current;
}
}
Expand Down Expand Up @@ -204,7 +204,7 @@ const OptionList: React.ForwardRefRenderFunction<RefOptionListProps, {}> = (_, r
case KeyCode.ENTER: {
// value
const item = memoFlattenOptions[activeIndex];
if (item && !item?.data?.disabled && !shouldDisabled) {
if (item && !item?.data?.disabled && !overMaxCount) {
onSelectValue(item.value);
} else {
onSelectValue(undefined);
Expand Down Expand Up @@ -262,8 +262,9 @@ const OptionList: React.ForwardRefRenderFunction<RefOptionListProps, {}> = (_, r

const renderItem = (index: number) => {
const item = memoFlattenOptions[index];
if (!item) return null;

if (!item) {
return null;
}
const itemData = item.data || {};
const { value } = itemData;
const { group } = item;
Expand Down Expand Up @@ -330,11 +331,11 @@ const OptionList: React.ForwardRefRenderFunction<RefOptionListProps, {}> = (_, r
const { disabled, title, children, style, className, ...otherProps } = data;
const passedProps = omit(otherProps, omitFieldNameList);

const mergedDisabled = disabled || shouldDisabled;

// Option
const selected = isSelected(value);

const mergedDisabled = disabled || (!selected && overMaxCount);

const optionPrefixCls = `${itemPrefixCls}-option`;
const optionClassName = classNames(itemPrefixCls, optionPrefixCls, className, {
[`${optionPrefixCls}-grouped`]: groupOption,
Expand Down

0 comments on commit ed199a5

Please sign in to comment.