gpt4 book ai didi

reactjs - 在 react-accessible-accordion 中单击最后一个 Accordion 项目时关闭它

转载 作者:行者123 更新时间:2023-12-05 06:02:12 25 4
gpt4 key购买 nike

我在 React 中有一个基本的 FAQ 组件。我的问题是当我打开一个 Accordion 项目时,我无法在单击它时再次将其关闭。我可以关闭 Accordion 的唯一方法是单击另一个问题。但我也想在点击问题时关闭它。这是我的代码:

import React from "react";
import {
Accordion,
AccordionItem,
AccordionItemHeading,
AccordionItemButton,
AccordionItemPanel,
} from "react-accessible-accordion";

import "react-accessible-accordion/dist/fancy-example.css";

export default function FAQ() {
return (
<>
<Accordion>
<AccordionItem>
<AccordionItemHeading>
<AccordionItemButton>Question 1</AccordionItemButton>
</AccordionItemHeading>
<AccordionItemPanel>
<p>
Exercitation in fugiat est ut ad ea cupidatat ut in cupidatat
occaecat ut occaecat consequat est minim minim esse tempor laborum
consequat esse adipisicing eu reprehenderit enim.
</p>
</AccordionItemPanel>
</AccordionItem>
<AccordionItem>
<AccordionItemHeading>
<AccordionItemButton>Question 2</AccordionItemButton>
</AccordionItemHeading>
<AccordionItemPanel>
<p>
Exercitation in fugiat est ut ad ea cupidatat ut in cupidatat
occaecat ut occaecat consequat est minim minim esse tempor laborum
consequat esse adipisicing eu reprehenderit enim.
</p>
</AccordionItemPanel>
</AccordionItem>
</Accordion>
</>
);
}

最佳答案

您需要向 Accordion 提供 bool 属性 allowZeroExpanded

 <Accordion allowZeroExpanded>
...
</Accordion>

它会让你关闭最后一个否则会一直打开的。看这个official demo .

关于reactjs - 在 react-accessible-accordion 中单击最后一个 Accordion 项目时关闭它,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66994784/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com