typescript 脉轮Ui allowMultiple={false}不工作

aor9mmx1  于 2023-04-22  发布在  TypeScript
关注(0)|答案(1)|浏览(80)

我如何解决我的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,但失败了。

7kqas0il

7kqas0il1#

官方:
“如果将allowMultiple设置为true,则Accordion将允许同时展开多个项目。”
示例链接:https://chakra-ui.com/docs/components/accordion/usage#expand-multiple-items-at-once

相关问题