【发布时间】:2021-03-30 07:55:38
【问题描述】:
我使用 Ant-design 折叠作为手风琴,我的要求是当我加载页面时默认第一个面板应该打开,并且当我点击其他面板时,无论面板已经打开应该关闭并且只有点击的面板应该展开.有人可以帮我解决这个问题吗?
我正在使用 Ant-design 折叠:
https://ant.design/components/collapse/
问候,
【问题讨论】:
我使用 Ant-design 折叠作为手风琴,我的要求是当我加载页面时默认第一个面板应该打开,并且当我点击其他面板时,无论面板已经打开应该关闭并且只有点击的面板应该展开.有人可以帮我解决这个问题吗?
我正在使用 Ant-design 折叠:
https://ant.design/components/collapse/
问候,
【问题讨论】:
您需要使用“accordion”和“defaultActiveKey”属性。比如:
import { Collapse } from 'antd';
const { Panel } = Collapse;
const text = `
A dog is a type of domesticated animal.
Known for its loyalty and faithfulness,
it can be found as a welcome guest in many households across the world.
`;
ReactDOM.render(
<Collapse accordion defaultActiveKey={['1']}>
<Panel header="This is panel header 1" key="1">
<p>{text}</p>
</Panel>
<Panel header="This is panel header 2" key="2">
<p>{text}</p>
</Panel>
<Panel header="This is panel header 3" key="3">
<p>{text}</p>
</Panel>
</Collapse>,
mountNode,
);
【讨论】:
defaultActiveKey={['0']},并且不需要在 Panels 上指定 keys 属性