我如何解决我的React项目中的Chakra UI Accordion在点击新的Accordion时没有关闭以前打开的Accordion的问题,即使我已经将“allowMultiple”prop设置为false?下面是我使用的代码:
export const ComponentName = ({Users}: any) => {
return (
<Box>
Users.map((user: any) => {
return (
<Accordion
key={user.imageUrl}
className="accordion"
allowToggle
allowMultiple={false}
>
<AccordionItem>
<AccordionButton className="accordionButton">
<Text className="userName">{user.name}</Text>
<Avatar src={user.img} />
</AccordionButton>
<AccordionPanel>
{user.topics.map((topic: any) => {
return <Tag className="topic">{topic}</Tag>;
})}
</AccordionPanel>
</AccordionItem>
</Accordion>
)
})
</Box>
)
}
我尝试使用isOpen和isExpended,但失败了。
1条答案
按热度按时间7kqas0il1#
官方:
“如果将allowMultiple设置为true,则Accordion将允许同时展开多个项目。”
示例链接:https://chakra-ui.com/docs/components/accordion/usage#expand-multiple-items-at-once