question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Collapse component: in property is not working when setting it initially to true

See original GitHub issue

Bug report

Describe the bug

The Collapse component isn’t open when specifying it.

To reproduce

Create a way of opening and closing the collapse with the initial state set as open. I’m using the useDisclosure hook.

const { isOpen, onToggle } = useDisclosure({ defaultIsOpen: true });

Create a button for opening and closing the collapse:

<Button onClick={onToggle} size={"sm"}>
    {isOpen ? "Hide" : "Show"} collapse
</Button>

Create a Collapse component and use the previous state you created.

<Collapse in={isOpen} animateOpacity>
...
</Collapse>

Go to the browser, there you can see that the collapse isn’t open by default. Once you click the button, the collapse will open and close very fast, then when you click the button for the 2nd time the collapse will work as expected.

Minimal reproduction

I created a repository with a minimal reproduction of the issue: https://github.com/javierriveros/chakra-collapse-issue

Expected behavior

Collapse should be open by default when I specify it using the state variable.

System information

Additional context

This was not a problem with the release candidate 1.0.0-rc8

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:9
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

4reactions
harshzalavadiyacommented, Nov 23, 2020

Temporary using unmountOnExit={true} will make it work as expected

2reactions
lunaticcodingcommented, Jul 3, 2022

@segunadebayo Took me quite a while to find this here 😃 the documentation on the website right here still calls the in argument isOpen. 😃 Maybe you could update it.

Read more comments on GitHub >

github_iconTop Results From Across the Web

bootstrap initially collapsed element - Stack Overflow
When you expand or collapse accordion it just adds/removes a class "in" and sets the height:auto or 0 to the accordion div.
Read more >
Collapse · Bootstrap v5.0
If you've set the collapsible element to be open by default using the show class, set aria-expanded="true" on the control instead.
Read more >
Mastering margin collapsing - CSS: Cascading Style Sheets
This applies to both adjacent elements and nested elements. Collapsing margins is only relevant in the vertical direction. Margins don't ...
Read more >
Expand and Collapse Nodes - DevExtreme - DevExpress
If a node is supposed to be expanded initially, set its expanded field to true. If another field specifies whether a node is...
Read more >
Collapse | Components - BootstrapVue
... an initially visible collapse will not animate on mount. To enable the collapse expanding animation on mount (when visible or v-model is...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found