Skip to content

Commit

Permalink
fix: optimize null check logic
Browse files Browse the repository at this point in the history
  • Loading branch information
aojunhao123 committed Dec 23, 2024
1 parent faa432b commit b23bfc2
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 30 deletions.
3 changes: 1 addition & 2 deletions src/OptionList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/TreeSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -629,7 +629,7 @@ const TreeSelect = React.forwardRef<BaseSelectRef, TreeSelectProps>((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,
Expand Down
27 changes: 0 additions & 27 deletions tests/Select.maxCount.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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(
<TreeSelect
treeData={treeData}
treeCheckable
treeDefaultExpandAll
multiple
maxCount={2}
showCheckedStrategy={TreeSelect.SHOW_ALL}
onChange={handleChange}
open
/>,
);

// 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', () => {
Expand Down

0 comments on commit b23bfc2

Please sign in to comment.