Skip to content
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

No easy way to control collapsible programmatically #431

Closed
mikix opened this issue Apr 30, 2019 · 3 comments
Closed

No easy way to control collapsible programmatically #431

mikix opened this issue Apr 30, 2019 · 3 comments
Assignees

Comments

@mikix
Copy link
Contributor

mikix commented Apr 30, 2019

Looks like it does listen to changes in the prop isOpen. But if I'm sitting here and want to ensure the collapsible is open, the only sure fire way to do that is to cycle the isOpen prop first to false and then to true.

@mikix mikix changed the title No easy way to controll collapsible programmatically No easy way to control collapsible programmatically Apr 30, 2019
@mikix
Copy link
Contributor Author

mikix commented May 1, 2019

Cycling isOpen to false then true didn't work - presumably I would have needed to give react a cycle of its event loop to handle the switch.

Instead, what worked was keeping track of internal collapsible state by listening to onToggle, and updating the input isOpen prop to match. Then, when I wanted to set to true, the Collapsible would notice because I was actually going from false to true.

Something simpler might be nicer? Though maybe you can't get too simple. If you add a method to do it, a consumer would need to grab a reference to the collapsible. But that might be less effort than keeping their own state and adding event handlers.

@abutterworth
Copy link
Contributor

abutterworth commented May 2, 2019

You're spot on with this. Many Paragon components keep an internal state for things like "isOpen" and try to merge it with props. Generally we shouldn't do this.

Though, in the case of a Collapsible I think it makes sense to have it be able handle it's own open/closed state. It sounds like we can improve the implementation. If a prop is passed in that should always overrule any internal state. I'll take a look.

@abutterworth abutterworth self-assigned this May 2, 2019
@abutterworth abutterworth reopened this Aug 22, 2019
@abutterworth
Copy link
Contributor

Fixed by #504

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants