Nativebase: Programmatically expand Accordion

Created on 19 Oct 2018  路  7Comments  路  Source: GeekyAnts/NativeBase

Is there anyway to programmatically expand the accordion?
I tried with set ref then setNativeProps({expanded: 0}) but failed instead.

Most helpful comment

I realize I'm a little late to the party, but I solved this issue today. Include a ref property in the Accordion, as follows:

<Accordion
  ref={c => (this._accordion = c)}
  dataArray={dataArray}
  renderHeader={this._filterHeader}
  renderContent={this._filterContent}
/>

Then, to programmatically expand a tab, you can do this:

this._accordion.setSelected(n); (where n is the index of the tab you would like to open)

To close all tabs, you can do this:

this._accordion.setSelected(-1);

This works with native-base v2.12.1.

All 7 comments

@fuj1w4r4
Try this way to expand the element at 2nd index of Accordion dataArray:

< Accordion
            expanded={2}
            dataArray={dataArray}
/>

Closing this issue due to inactivity
Reopen this issue if help needed

Hi, also facing the same problem I would like to expand/ collapse the accordion when a certain event takes place..

I realize I'm a little late to the party, but I solved this issue today. Include a ref property in the Accordion, as follows:

<Accordion
  ref={c => (this._accordion = c)}
  dataArray={dataArray}
  renderHeader={this._filterHeader}
  renderContent={this._filterContent}
/>

Then, to programmatically expand a tab, you can do this:

this._accordion.setSelected(n); (where n is the index of the tab you would like to open)

To close all tabs, you can do this:

this._accordion.setSelected(-1);

This works with native-base v2.12.1.

@grahamyesfit

in my case this. _accordion is null

@grahamyesfit accordionRef.setSelected is not a function. Native base 2.13.8
Screenshot_1579806642

current was missing. This works thanks!
accordionRef.current.setSelected(0);

Was this page helpful?
0 / 5 - 0 ratings

Related issues

agersoncgps picture agersoncgps  路  3Comments

bsiddiqui picture bsiddiqui  路  3Comments

maphongba008 picture maphongba008  路  3Comments

aloifolia picture aloifolia  路  3Comments

muthuraman007 picture muthuraman007  路  3Comments