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 29, 2023
1 parent 561b4c6 commit 95ad2dc
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/BaseSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ const BaseSelect = React.forwardRef<BaseSelectRef, BaseSelectProps>((props, ref)
[tokenSeparators],
);

const { isValidMaxCount, overMaxCount, diff } = useOverMaxCount();
const { isValidMaxCount, overMaxCount, diff } = useOverMaxCount(multiple);

const onInternalSearch = (searchText: string, fromTyping: boolean, isCompositing: boolean) => {
if (isValidMaxCount && overMaxCount) {
Expand Down
2 changes: 1 addition & 1 deletion 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 { isValidMaxCount, overMaxCount } = useOverMaxCount();
const { isValidMaxCount, overMaxCount } = useOverMaxCount(multiple);

const mergedOverMaxCount = isValidMaxCount && overMaxCount;

Expand Down
6 changes: 2 additions & 4 deletions src/hooks/useOverMaxCount.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
import React from 'react';
import useBaseProps from './useBaseProps';
import SelectContext from '../SelectContext';
import type { SelectContextProps } from '../SelectContext';

const useOverMaxCount = () => {
const { multiple } = useBaseProps() || {};
const useOverMaxCount = (multiple: boolean) => {
const { maxCount, rawValues } = React.useContext<SelectContextProps>(SelectContext) || {};
return React.useMemo(
() => ({
isValidMaxCount: multiple && typeof maxCount !== 'undefined',
overMaxCount: rawValues?.size >= maxCount,
diff: maxCount - rawValues?.size,
}),
[maxCount, multiple, rawValues?.size],
[multiple, maxCount, rawValues?.size],
);
};

Expand Down

0 comments on commit 95ad2dc

Please sign in to comment.