Skip to content

Commit c93ff10

Browse files
authored
chore: add isValidCount (#1017)
1 parent 9a7fc96 commit c93ff10

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

src/BaseSelect.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import Selector from './Selector';
2727
import type { RefTriggerProps } from './SelectTrigger';
2828
import SelectTrigger from './SelectTrigger';
2929
import TransBtn from './TransBtn';
30-
import { getSeparatedContent } from './utils/valueUtil';
30+
import { getSeparatedContent, isValidCount } from './utils/valueUtil';
3131
import SelectContext from './SelectContext';
3232
import type { SelectContextProps } from './SelectContext';
3333

@@ -399,7 +399,7 @@ const BaseSelect = React.forwardRef<BaseSelectRef, BaseSelectProps>((props, ref)
399399
const { maxCount, rawValues } = React.useContext<SelectContextProps>(SelectContext) || {};
400400

401401
const onInternalSearch = (searchText: string, fromTyping: boolean, isCompositing: boolean) => {
402-
if (rawValues?.size >= maxCount) {
402+
if (isValidCount(maxCount) && rawValues?.size >= maxCount) {
403403
return;
404404
}
405405
let ret = true;
@@ -409,7 +409,7 @@ const BaseSelect = React.forwardRef<BaseSelectRef, BaseSelectProps>((props, ref)
409409
const separatedList = getSeparatedContent(
410410
searchText,
411411
tokenSeparators,
412-
maxCount && maxCount - rawValues.size,
412+
isValidCount(maxCount) ? maxCount - rawValues.size : undefined,
413413
);
414414

415415
// Check if match the `tokenSeparators`

src/OptionList.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import TransBtn from './TransBtn';
1414
import useBaseProps from './hooks/useBaseProps';
1515
import type { FlattenOptionData } from './interface';
1616
import { isPlatformMac } from './utils/platformUtil';
17+
import { isValidCount } from './utils/valueUtil';
1718

1819
// export interface OptionListProps<OptionsType extends object[]> {
1920
export type OptionListProps = Record<string, never>;
@@ -72,7 +73,7 @@ const OptionList: React.ForwardRefRenderFunction<RefOptionListProps, {}> = (_, r
7273
const listRef = React.useRef<ListRef>(null);
7374

7475
const overMaxCount = React.useMemo<boolean>(
75-
() => multiple && typeof maxCount !== 'undefined' && rawValues?.size >= maxCount,
76+
() => multiple && isValidCount(maxCount) && rawValues?.size >= maxCount,
7677
[multiple, maxCount, rawValues?.size],
7778
);
7879

src/utils/valueUtil.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ function getKey(data: BaseOptionType, index: number) {
2020
return `rc-index-key-${index}`;
2121
}
2222

23+
export function isValidCount(value?: number) {
24+
return typeof value !== 'undefined' && !Number.isNaN(value);
25+
}
26+
2327
export function fillFieldNames(fieldNames: FieldNames | undefined, childrenAsData: boolean) {
2428
const { label, value, options, groupLabel } = fieldNames || {};
2529
const mergedLabel = label || (childrenAsData ? 'children' : 'label');

0 commit comments

Comments
 (0)