Skip to content

Commit b23bfc2

Browse files
committed
fix: optimize null check logic
1 parent faa432b commit b23bfc2

File tree

3 files changed

+2
-30
lines changed

3 files changed

+2
-30
lines changed

src/OptionList.tsx

+1-2
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,9 @@ import useMemo from 'rc-util/lib/hooks/useMemo';
99
import * as React from 'react';
1010
import LegacyContext from './LegacyContext';
1111
import TreeSelectContext from './TreeSelectContext';
12-
import type { DataNode, FieldNames, Key, SafeKey } from './interface';
12+
import type { DataNode, Key, SafeKey } from './interface';
1313
import { getAllKeys, isCheckDisabled } from './utils/valueUtil';
1414
import { useEvent } from 'rc-util';
15-
import { formatStrategyValues } from './utils/strategyUtil';
1615

1716
const HIDDEN_STYLE = {
1817
width: 0,

src/TreeSelect.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -629,7 +629,7 @@ const TreeSelect = React.forwardRef<BaseSelectRef, TreeSelectProps>((props, ref)
629629
treeExpandAction,
630630
treeTitleRender,
631631
onPopupScroll,
632-
leftMaxCount: maxCount ? maxCount - cachedDisplayValues.length : null,
632+
leftMaxCount: maxCount === undefined ? null : maxCount - cachedDisplayValues.length,
633633
leafCountOnly:
634634
mergedShowCheckedStrategy === 'SHOW_CHILD' && !treeCheckStrictly && !!treeCheckable,
635635
valueEntities,

tests/Select.maxCount.spec.tsx

-27
Original file line numberDiff line numberDiff line change
@@ -271,33 +271,6 @@ describe('TreeSelect.maxCount with different strategies', () => {
271271
fireEvent.click(childCheckboxes[2]);
272272
expect(handleChange).toHaveBeenCalledTimes(2);
273273
});
274-
275-
it('should respect maxCount with SHOW_ALL strategy', () => {
276-
const handleChange = jest.fn();
277-
const { container } = render(
278-
<TreeSelect
279-
treeData={treeData}
280-
treeCheckable
281-
treeDefaultExpandAll
282-
multiple
283-
maxCount={2}
284-
showCheckedStrategy={TreeSelect.SHOW_ALL}
285-
onChange={handleChange}
286-
open
287-
/>,
288-
);
289-
290-
// Select parent node - should not work as it would show both parent and children
291-
const parentCheckbox = within(container).getByText('parent');
292-
fireEvent.click(parentCheckbox);
293-
expect(handleChange).not.toHaveBeenCalled();
294-
295-
// Select individual children
296-
const childCheckboxes = within(container).getAllByText(/child/);
297-
fireEvent.click(childCheckboxes[0]);
298-
fireEvent.click(childCheckboxes[1]);
299-
expect(handleChange).toHaveBeenCalledTimes(2);
300-
});
301274
});
302275

303276
describe('TreeSelect.maxCount with treeCheckStrictly', () => {

0 commit comments

Comments
 (0)