triniwiz / nativescript-accordion

Apache License 2.0
38 stars 14 forks source link

itemContentTap returns wrong childIndex / data #54

Open manojdcoder opened 5 years ago

manojdcoder commented 5 years ago

itemContentTap returns wrong childIndex / data, clicking on 0th index returns 1 at childIndex and data from 1st index. If I click on last content item, data will be undefined.

Which platform(s) does your issue occur on?

Please, provide the following version numbers that your issue occurs with:

Please, tell us how to recreate the issue in as much detail as possible.

Describe the steps to reproduce it.

Is there any code involved?

HTML

 <Accordion class="list-group" [items]="groups"
            (itemContentTap)="onItemContentTap($event)">
            <ng-template let-group="item" acTemplateKey="title">
                <GridLayout class="p-10 bg-muted header-separator">
                    <Label class="font-weight-bold" [text]="group.title"></Label>
                </GridLayout>
            </ng-template>
            <ng-template let-item="item" acTemplateKey="content">
                <Label class="list-group-item" [text]="item.display"></Label>
            </ng-template>
        </Accordion>

TS

 groups: { title: string, items: { display: string }[] }[] = [
    {
        title: "Group 1",
        items: [
              { display: "Item 1" },
              { display: "Item 2" },
              { display: "Item 3" },
        ]
    },
   {
        title: "Group 2",
        items: [
              { display: "Item 1" },
              { display: "Item 2" },
              { display: "Item 3" },
        ]
    }
];

  onItemContentTap(event) {
        const data = event.data;
        console.log(event.index);
        console.log(event.childIndex); // Index is always one more than what user taps
        console.log(data);  
    }
asologor commented 5 years ago

Same here. Indexing starts from 1 instead of 0 on iOS only.

hakkism commented 5 years ago

Any workaround here?