Skip to content

Commit bbb2fae

Browse files
authoredMar 19, 2025··
fix(thought-chain): controlled mode not working
close #590
1 parent 70142f1 commit bbb2fae

File tree

2 files changed

+36
-5
lines changed

2 files changed

+36
-5
lines changed
 

‎components/thought-chain/__tests__/index.test.tsx

+29-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import React from 'react';
2+
import { fireEvent, render } from '../../../tests/utils';
23
import ThoughtChain from '../index';
3-
import { render, fireEvent } from '../../../tests/utils';
44

5+
import { CheckCircleOutlined } from '@ant-design/icons';
56
import mountTest from '../../../tests/shared/mountTest';
67
import rtlTest from '../../../tests/shared/rtlTest';
78
import themeTest from '../../../tests/shared/themeTest';
8-
import { CheckCircleOutlined } from '@ant-design/icons';
99

1010
import type { ThoughtChainItem } from '../index';
1111

@@ -84,4 +84,31 @@ describe('ThoughtChain Component', () => {
8484
fireEvent.click(element as Element);
8585
expect(onExpand).toHaveBeenCalledWith([]);
8686
});
87+
88+
it('ThoughtChain component work with controlled mode', () => {
89+
const App = () => {
90+
const [expandedKeys] = React.useState<string[]>(['test3']);
91+
92+
return (
93+
<ThoughtChain
94+
items={items}
95+
collapsible={{
96+
expandedKeys,
97+
}}
98+
/>
99+
);
100+
};
101+
const { container } = render(<App />);
102+
const element = container.querySelectorAll<HTMLDivElement>(
103+
'.ant-thought-chain-item-header-box',
104+
)[0];
105+
106+
fireEvent.click(element as Element);
107+
108+
const expandBodyElements = container.querySelectorAll<HTMLDivElement>(
109+
'.ant-thought-chain-item .ant-thought-chain-item-content',
110+
);
111+
112+
expect(expandBodyElements).toHaveLength(1);
113+
});
87114
});

‎components/thought-chain/hooks/useCollapsible.ts

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import React from 'react';
21
import useMergedState from 'rc-util/lib/hooks/useMergedState';
2+
import React from 'react';
33
import initCollapseMotion from '../../_util/motion';
44

55
import type { CSSMotionProps } from 'rc-motion';
@@ -53,8 +53,12 @@ const useCollapsible: UseCollapsible = (collapsible, prefixCls, rootPrefixCls) =
5353
}, [collapsible]);
5454

5555
// ============================ ExpandedKeys ============================
56-
const [mergedExpandedKeys, setMergedExpandedKeys] =
57-
useMergedState<RequiredCollapsibleOptions['expandedKeys']>(customizeExpandedKeys);
56+
const [mergedExpandedKeys, setMergedExpandedKeys] = useMergedState<
57+
RequiredCollapsibleOptions['expandedKeys']
58+
>([], {
59+
value: customizeExpandedKeys,
60+
onChange: customizeOnExpand,
61+
});
5862

5963
// ============================ Event ============================
6064
const onItemExpand = (curKey: string) => {

0 commit comments

Comments
 (0)
Please sign in to comment.