Skip to content

Commit 83b3e0b

Browse files
committed
fix(thought-chain): 非受控模式无法工作
1 parent 2d8c45e commit 83b3e0b

File tree

2 files changed

+30
-4
lines changed

2 files changed

+30
-4
lines changed

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

+19
Original file line numberDiff line numberDiff line change
@@ -111,4 +111,23 @@ describe('ThoughtChain Component', () => {
111111

112112
expect(expandBodyElements).toHaveLength(1);
113113
});
114+
115+
it('ThoughtChain component work with uncontrolled mode', () => {
116+
const App = () => {
117+
return <ThoughtChain items={items} collapsible />;
118+
};
119+
120+
const { container } = render(<App />);
121+
const element = container.querySelectorAll<HTMLDivElement>(
122+
'.ant-thought-chain-item-header-box',
123+
)[0];
124+
125+
fireEvent.click(element as Element);
126+
127+
const expandBodyElements = container.querySelectorAll<HTMLDivElement>(
128+
'.ant-thought-chain-item .ant-thought-chain-item-content',
129+
);
130+
131+
expect(expandBodyElements).toHaveLength(1);
132+
});
114133
});

components/thought-chain/hooks/useCollapsible.ts

+11-4
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,19 @@ const useCollapsible: UseCollapsible = (collapsible, prefixCls, rootPrefixCls) =
5353
}, [collapsible]);
5454

5555
// ============================ ExpandedKeys ============================
56+
const collapsibleIsTrue = collapsible === true;
5657
const [mergedExpandedKeys, setMergedExpandedKeys] = useMergedState<
5758
RequiredCollapsibleOptions['expandedKeys']
58-
>([], {
59-
value: customizeExpandedKeys,
60-
onChange: customizeOnExpand,
61-
});
59+
>(
60+
customizeExpandedKeys,
61+
collapsibleIsTrue
62+
? undefined
63+
: {
64+
defaultValue: customizeExpandedKeys,
65+
value: customizeExpandedKeys,
66+
onChange: customizeOnExpand,
67+
},
68+
);
6269

6370
// ============================ Event ============================
6471
const onItemExpand = (curKey: string) => {

0 commit comments

Comments
 (0)