From b23bfc2072b01c3a5a03a96d7a9685a76858e747 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E8=B1=AA?= <1844749591@qq.com> Date: Mon, 23 Dec 2024 15:41:49 +0800 Subject: [PATCH] fix: optimize null check logic --- src/OptionList.tsx | 3 +-- src/TreeSelect.tsx | 2 +- tests/Select.maxCount.spec.tsx | 27 --------------------------- 3 files changed, 2 insertions(+), 30 deletions(-) diff --git a/src/OptionList.tsx b/src/OptionList.tsx index 3c0e4434..d69aec40 100644 --- a/src/OptionList.tsx +++ b/src/OptionList.tsx @@ -9,10 +9,9 @@ import useMemo from 'rc-util/lib/hooks/useMemo'; import * as React from 'react'; import LegacyContext from './LegacyContext'; import TreeSelectContext from './TreeSelectContext'; -import type { DataNode, FieldNames, Key, SafeKey } from './interface'; +import type { DataNode, Key, SafeKey } from './interface'; import { getAllKeys, isCheckDisabled } from './utils/valueUtil'; import { useEvent } from 'rc-util'; -import { formatStrategyValues } from './utils/strategyUtil'; const HIDDEN_STYLE = { width: 0, diff --git a/src/TreeSelect.tsx b/src/TreeSelect.tsx index 31044b37..1a8a938d 100644 --- a/src/TreeSelect.tsx +++ b/src/TreeSelect.tsx @@ -629,7 +629,7 @@ const TreeSelect = React.forwardRef((props, ref) treeExpandAction, treeTitleRender, onPopupScroll, - leftMaxCount: maxCount ? maxCount - cachedDisplayValues.length : null, + leftMaxCount: maxCount === undefined ? null : maxCount - cachedDisplayValues.length, leafCountOnly: mergedShowCheckedStrategy === 'SHOW_CHILD' && !treeCheckStrictly && !!treeCheckable, valueEntities, diff --git a/tests/Select.maxCount.spec.tsx b/tests/Select.maxCount.spec.tsx index 31a9a68b..1f9c74e9 100644 --- a/tests/Select.maxCount.spec.tsx +++ b/tests/Select.maxCount.spec.tsx @@ -271,33 +271,6 @@ describe('TreeSelect.maxCount with different strategies', () => { fireEvent.click(childCheckboxes[2]); expect(handleChange).toHaveBeenCalledTimes(2); }); - - it('should respect maxCount with SHOW_ALL strategy', () => { - const handleChange = jest.fn(); - const { container } = render( - , - ); - - // Select parent node - should not work as it would show both parent and children - const parentCheckbox = within(container).getByText('parent'); - fireEvent.click(parentCheckbox); - expect(handleChange).not.toHaveBeenCalled(); - - // Select individual children - const childCheckboxes = within(container).getAllByText(/child/); - fireEvent.click(childCheckboxes[0]); - fireEvent.click(childCheckboxes[1]); - expect(handleChange).toHaveBeenCalledTimes(2); - }); }); describe('TreeSelect.maxCount with treeCheckStrictly', () => {