使用语义UI React打开多个手风琴可以通过以下步骤实现:
npm install semantic-ui-react
import { Accordion } from 'semantic-ui-react';
import 'semantic-ui-css/semantic.min.css';
const [activeIndex, setActiveIndex] = useState([]);
const handleAccordionClick = (e, titleProps) => {
const { index } = titleProps;
const newIndex = activeIndex.includes(index)
? activeIndex.filter(item => item !== index)
: [...activeIndex, index];
setActiveIndex(newIndex);
};
<Accordion>
<Accordion.Title
active={activeIndex.includes(0)}
index={0}
onClick={handleAccordionClick}
>
<Icon name='dropdown' />
手风琴1
</Accordion.Title>
<Accordion.Content active={activeIndex.includes(0)}>
手风琴1的内容
</Accordion.Content>
<Accordion.Title
active={activeIndex.includes(1)}
index={1}
onClick={handleAccordionClick}
>
<Icon name='dropdown' />
手风琴2
</Accordion.Title>
<Accordion.Content active={activeIndex.includes(1)}>
手风琴2的内容
</Accordion.Content>
{/* 添加更多手风琴项 */}
</Accordion>
通过以上步骤,你可以使用语义UI React创建多个手风琴,并实现打开和关闭的功能。每个手风琴项都有一个标题和内容,点击标题可以展开或折叠对应的内容。
腾讯云相关产品和产品介绍链接地址:
领取专属 10元无门槛券
手把手带您无忧上云