Skip to content

<Accordion.Panel isOpen={true}> doesn't work also setOpen and isOpen doesn't work with props #735

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
iliafaramarzpour opened this issue May 10, 2023 · 22 comments · May be fixed by #775
Open
Labels
🐛 bug Something isn't working confirmed This bug was confirmed help wanted Extra attention is needed
Milestone

Comments

@iliafaramarzpour
Copy link

Describe the bug
In the project, I need to manage the accordions panel and be able to open and close them, but I can't, I also checked the Flowbite codes and realized that they are not written correctly.

Expected behavior
I want to manage isOpen and setOpen from the accordion panel and they work correctly.

Screenshots
Screenshot 2023-05-10 at 3 01 34 PM

System information:

  • Device: Mac
  • Browser: Chrome

Project information:

  • Tailwind: ^3.2.4
  • Flowbite: ^1.6.0
  • Flowbite React: ^0.4.2
  • Type: Next.js - 13.4.1
@rluders
Copy link
Collaborator

rluders commented May 10, 2023

Sorry, I don't get the problem. Can you give more details?
All the examples inside the documentation page seem to work properly.

You can get the source code to the examples here: https://github.com/themesberg/flowbite-react/blob/main/src/docs/pages/AccordionPage.tsx

PS: If you cold add a video demonstrating the problem, it would be better to understand, or to provide a sample project.

@iliafaramarzpour
Copy link
Author

Sorry, I don't get the problem. Can you give more details? All the examples inside the documentation page seem to work properly.

You can get the source code to the examples here: https://github.com/themesberg/flowbite-react/blob/main/src/docs/pages/AccordionPage.tsx

PS: If you cold add a video demonstrating the problem, it would be better to understand, or to provide a sample project.

I have a form for the user's profile in each accordion panel, and I want the user to see a SAVE button at the end of each accordion panel and open the next accordion panel after clicking the button. It means that I can control which accordion panel is open with a state and manage its opening and closing.

@iliafaramarzpour
Copy link
Author

Sorry, I don't get the problem. Can you give more details? All the examples inside the documentation page seem to work properly.

You can get the source code to the examples here: https://github.com/themesberg/flowbite-react/blob/main/src/docs/pages/AccordionPage.tsx

PS: If you cold add a video demonstrating the problem, it would be better to understand, or to provide a sample project.

please read this : https://github.com/themesberg/flowbite-react/tree/main/src/lib/components/Accordion 
And see how the logic of isOpen and setOpen is written in Accordion.tsx and AccordionPanel.tsx files.

@rluders
Copy link
Collaborator

rluders commented May 13, 2023

I still don't get it. Can you provide an example project?

@realvandi
Copy link

realvandi commented May 22, 2023

I'm also having this problem myself. In a very simple use case:

const [isOpen, setIsOpen] = useState(false);
  const toggleAccordion = () => {
    setIsOpen(!isOpen);
    console.log(isOpen)
  };
  return (
   <>
    <Accordion>
      <AccordionPanel isOpen={isOpen}>
        <AccordionTitle theme={accordionTitleTheme}>Hello</AccordionTitle>
        <AccordionContent>World</AccordionContent>
      </AccordionPanel>
    </Accordion>
          <Button onClick={toggleAccordion}>
          {isOpen ? 'Close Accordion' : 'Open Accordion'}
        </Button>
        </>);

Does not seem to open or close the accordion panel accordingly. The isOpen state is being changed, but the state is not being reflected by the accordionPanel.

@realvandi
Copy link

To note here is that I've also attempted using the setOpen prop for AccordionPanel, which imo is lacking documentation on how it's supposed to be used. As someone trying to use AccordionPanel, the setOpen prop is lacking description on how it's supposed to be used, and what it's for.

@rluders
Copy link
Collaborator

rluders commented May 22, 2023

@realvandi documentation update should be coming soon. The library wasn't released yet, so, it is expected to have missing documentation, but the code is always your best friend in this case.

@realvandi
Copy link

realvandi commented May 22, 2023

@rluders thanks for the quick response, it's very much appreciated. In the meanwhile, any hints on what could be done in order to trigger the opening/closing of the AccordionPanel? I can't seem to figure out what's wrong, even after reading through the code. Any answer would be much appreciated, thanks again for responding

@rluders
Copy link
Collaborator

rluders commented May 22, 2023

@IuriPires can you help on this one? I'm not sure when I'll have time to test it right now.

@IuriPires
Copy link
Contributor

@IuriPires can you help on this one? I'm not sure when I'll have time to test it right now.

Sure!!

@IuriPires IuriPires linked a pull request May 27, 2023 that will close this issue
15 tasks
@rluders
Copy link
Collaborator

rluders commented Jul 25, 2023

Could someone confirm if the issue still exists?

@mwesterham
Copy link

Stumbled upon this thread since I ran into the same problem. I believe this is still an issue. My use case calls for the accordion panels to default open.

    <Accordion alwaysOpen>
      <Accordion.Panel isOpen={true}>
        <Accordion.Title>
          One
        </Accordion.Title>
        <Accordion.Content>
          1
        </Accordion.Content>
      </Accordion.Panel>
      <Accordion.Panel isOpen={true}>
        <Accordion.Title>
          Two
        </Accordion.Title>
        <Accordion.Content>
          2
        </Accordion.Content>
      </Accordion.Panel>
    </Accordion>

Here, only the "One" accordion panel is open when both should be open. I am using the latest npm version [email protected]

@rluders rluders added 🐛 bug Something isn't working help wanted Extra attention is needed confirmed This bug was confirmed labels Jul 27, 2023
@rluders rluders added this to the 1.0.0 milestone Jul 27, 2023
@mikeknapp
Copy link

I believe the setOpen callback may also not fire as well. (I assume this is meant to fire when the panel opens?)

@mcwachanga
Copy link

mcwachanga commented Sep 27, 2023

Is this working? I'm trying the isOpen prop and it's not responding. Please help

<Accordion>
      <Accordion.Panel itemID="panel1" >
        <Accordion.Title>Panel 1</Accordion.Title>
        <Accordion.Content>          
          panel 1 content
        </Accordion.Content>
      </Accordion.Panel>
      <Accordion.Panel itemID="panel2" isOpen={true}>
        <Accordion.Title>Panel 2</Accordion.Title>
        <Accordion.Content>          
          panel 2 content
        </Accordion.Content>
      </Accordion.Panel>
</Accordion>

@dima-kov
Copy link

anyone managed to make it work?

@bonesoul
Copy link

bonesoul commented Apr 5, 2024

I'm also having the issue. any one got a fix?

@MrMavin
Copy link

MrMavin commented May 23, 2024

Same issue here

@s0ngyang
Copy link

s0ngyang commented Jun 4, 2024

same issue here, trying to use isOpen to make all panels open by default but it is not working

@ChoiSeongmuk
Copy link

ChoiSeongmuk commented Jul 31, 2024

In my Case I was tried to use accordion with map iterator but it does not work properly.

I hope this usage can help someone.

const [isClosed, setIsClosed] = useState<boolean[]>(matchedHistory.map(() => true)); 

const handleOpen = (index: number) => {
    const newIsClosed = [...isClosed];
    newIsClosed[index] = !isClosed[index];
    setIsClosed(newIsClosed);
  };

  const handleOnPanel = (index: number) => {
    setIsClosed(items.map(() => true));
  };


<Accordion collapseAll arrowIcon={() => null}> // Remove existing default arrowIcon
      { items.map((item,index) => (
            <Accordion.Panel key={index}>
             <Accordion.Title
            onClick={() => handleOpen(index)}
          >
              <span>{Items.title}</span> 
              <AccordionArrow isOpen={!isClosed[index]} /> // AccordionArrowIcon goes here
          </Accordion.Title>
          <Accordion.Content hidden={isClosed[index]}> //  Decide the content to hide or shown
            <p>
              <b>item.content</b> 
            </p>
          <Button onClick={() => handleOnPanel(index)}>�SomeButton</Button>
          </Accordion.Content>
        </Accordion.Panel>
      ))}
</Accordion>
    

And this is arrow icon component above.
Just incase you want to use library here is url
clsx
twMerge


const AccordionArrow = ({ isOpen }: { isOpen: boolean }) => (
    <svg
      stroke="currentColor"
      fill="currentColor"
      strokeWidth="0"
      viewBox="0 0 20 20"
      aria-hidden="true"
      className={twMerge(
        "h-6 w-6 shrink-0",
        clsx(isOpen ? "rotate-180" : "rotate-0"),
      )}
      data-testid="flowbite-accordion-arrow"
      xmlns="http://www.w3.org/2000/svg"
    >
      <path
        fillRule="evenodd"
        d="M5.293 7.293a1 1 0 011.414 0L10 10.586l3.293-3.293a1 1 0 111.414 1.414l-4 4a1 1 0 01-1.414 0l-4-4a1 1 0 010-1.414z"
        clipRule="evenodd"
      ></path>
    </svg>
  );

@samjimenez-max
Copy link

This is still an issue, have not found a workaround

@kelnos
Copy link

kelnos commented Apr 2, 2025

I'm running into this as well, version 0.11.1 here. Do we know if #1404 fixes the issue, assuming it hasn't bitrotted? Odd that it hasn't even been commented on.

@SutuSebastian
Copy link
Collaborator

Unfortunately we'll have to rewrite the component from scratch, entirely, the current state its... yeah, not much to say.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 bug Something isn't working confirmed This bug was confirmed help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.