nextui-org / next-app-template

A Next.js 14 with app directory template pre-configured with NextUI (v2) and Tailwind CSS.
https://nextui-app.vercel.app
MIT License
301 stars 72 forks source link

[BUG] - `Accordion` doesn't handle `selectedKeys` changes #5

Closed wolkyura closed 1 year ago

wolkyura commented 1 year ago

NextUI Version

2.0.19

Describe the bug

It's only possible to update accordion selection through the onSelectionChange handler. I have attached a link to a codesandbox demonstrating a simple example where accordions are used as steps with Back/Next buttons. When trying to change selectedKeys - nothing happens.

  const [selectedKeys, setSelectedKeys] = React.useState<Selection>(new Set(["1"]));

  return (
    <Accordion
      selectedKeys={selectedKeys}
      onSelectionChange={setSelectedKeys}
    >
      <AccordionItem key="1" aria-label="Accordion 1" title="Accordion 1">
        <Button onClick={() => setSelectedKeys(new Set(["2"]))}>Next</Button>
      </AccordionItem>
    </Accordion>
)

Your Example Website or App

https://codesandbox.io/p/sandbox/reverent-maria-vr8229

Steps to Reproduce the Bug or Issue

  1. Click on the link to sandbox
  2. See accordions
  3. Click on the "Next" button

Expected behavior

I'd expect that it's possible to update selectedKeys from any handler by just returning new Set of values (new Set())

Screenshots or Videos

No response

Operating System Version

macOS 12.3.1

Browser

Chrome

wolkyura commented 1 year ago

Closing, as the issue was reopened in nextui repo