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

Programmatically toggle accordion #28

Closed
jamesl1001 opened this issue Jan 24, 2020 · 7 comments
Closed

Programmatically toggle accordion #28

jamesl1001 opened this issue Jan 24, 2020 · 7 comments
Assignees
Labels
enhancement New feature or request

Comments

@jamesl1001
Copy link

Is there a way to programmatically toggle the accordion without having to press on the header?

I want to have the first accordion in my FlatList always open on mount, so I tried this, but it does not work:

componentDidMount() {
    if (this.props.index === 0) {
        this.setState({
            collapsed: false,
        })
    }
}

collapsed in state is successfully toggled but the accordion does not open, presumably because the internal variable show is only toggled onPress.

@marouanekadiri marouanekadiri added the enhancement New feature or request label Jan 27, 2020
@marouanekadiri
Copy link
Owner

I'll work on that.

@marouanekadiri
Copy link
Owner

@jamesl1001 released in version 0.2.7.
Just use the key-based or index-based props expandedKey or expandedIndex to set the default expanded item.

@jamesl1001
Copy link
Author

jamesl1001 commented Jan 28, 2020

Wow thanks for the very fast turnaround @marouanekadiri!

I can see the documentation has been updated for the AccordionList component.

Does this also work for the Collapse component?

@marouanekadiri
Copy link
Owner

Hi @jamesl1001,
For Collapse you can use isCollapsed prop to specify the state of the component if it's expanded or collapsed.
By the way, I tried to clarify that in the documentation. But if you think that the documentation is poor. I highly welcome your contribution.
Thanks 😄

@jamesl1001
Copy link
Author

Thank you @marouanekadiri! I think I just missed that prop in the docs.

I would however advise that you reverse the isCollapsed boolean. Because the word "collapsed" usually means the accordion should be closed.

@markrickert
Copy link

markrickert commented Oct 23, 2020

Thank you @marouanekadiri! I think I just missed that prop in the docs.

I would however advise that you reverse the isCollapsed boolean. Because the word "collapsed" usually means the accordion should be closed.

This bit me today as i was playing around with the component i would expect isCollapsed={false) would mean that the body is OPEN but in practice it behaves the opposite. Using isCollapsed={true) seems to open it. 🤷

@marouanekadiri
Copy link
Owner

@markrickert True, It was actually my mistake 🙈 . Now, I'm thinking about releasing a breaking change version to switch to isExpanded or to change the behavior of isCollapsed.

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

No branches or pull requests

3 participants