[BUG] - `Accordion` doesn't handle `selectedKeys` changes
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
- Click on the link to sandbox
- See accordions
- 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
As given in the documentation in https://nextui.org/docs/components/accordion, the type for selectedKeys should be React.Key[] and not a Set. Then, the rest should work fine.
I tried to change Set() to string[], but it didn't work either (https://codesandbox.io/p/sandbox/busy-leftpad-5xy9p6).
The example of controlled Acoordion uses new Set() (https://nextui.org/docs/components/accordion#controlled):
Also, I think it's a bit confusing that state and setter have different types
Yeah, this is a bug. What I think is happening is that the onSelectionChange doesn't pass through the state change to the actual rendered component.
Hey guys, we're looking into this, but yes it is a bug. Thanks, @wolkyura for reporting it