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.

[Accordion] Callback function onOpen / onClose

See original GitHub issue

Is there a way to set a callback function when I open or close an item in Accordion? It would be nice to have the index of the opened/closed item and let us being able to do stuff with it.

I tried to achieve such a thing in a custom renderHeader function:

renderHeader(title, expanded) {
    return (
        <View onPress={() => console.log(expanded)}>
            <Text>{title}</Text>
        </View>
    )
}

It doesn’t work: the onPress function is not triggered. I tried to replace the <View /> by a <TouchableOpacity /> and the onPress function is triggered ; but the item doesn’t expand anymore.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:6
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

5reactions
pistoucommented, Dec 20, 2018

If I take the sample code provided in the documentation, it would be nice to be abble to have something like this working:

<Accordion
  dataArray={dataArray}
  expanded={0}
  onItemPress={(index, item) => {
    // do whatever
  }}
  />

Where index is the index of the header pressed and item is equivalent to dataArray[index]. It would be great to also have an onOpen() and onClose() or even better onBeforeOpen(), onAfterOpen(), onBeforeClose(), onAfterClose().

0reactions
sg28commented, Apr 9, 2019

Need this else will have to leave the accordion from native base. very important feature for mobile development

Read more comments on GitHub >

github_iconTop Results From Across the Web

jQuery accordion - OnCollapse and OnExpand events
What I'd like is to bind an event on accordion open and accordion close... Actually what I'd like to achieve is to do...
Read more >
Angular PrimeNG Accordion Events - GeeksforGeeks
onOpen : It is a callback function called when a tab is opened. onClose: Callback function is called when the active tab is...
Read more >
Accordion API - Material UI - MUI
API reference docs for the React Accordion component. Learn about the props, CSS, ... Callback fired when the expand/collapse state is changed. Signature:...
Read more >
Accordion Item #2 - React-Bootstrap
Click the accordions below to expand/collapse the accordion content. ... onExit. function. Callback fired before the component collapses. onExited. function.
Read more >
Accordion | Mobify DevCenter
Triggered by the user clicking on the opened header ( AccordionItem ). The onClose function is called with the item's ID passed to...
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