Skip to content

Commit 20fe57d

Browse files
authored
Merge pull request yannbf#59 from jeronimonascimento/feature/expanded-accordion-list
feat(accordion-list): possibility to set accordion's initial state as expanded
2 parents 0b88cb0 + 781a952 commit 20fe57d

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

src/components/accordion-list/accordion-list.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,20 @@ export class AccordionListComponent {
1010
@Input() contentColor: string = '#F9F9F9';
1111
@Input() title: string;
1212
@Input() hasMargin: boolean = true;
13+
@Input() expanded: boolean;
1314

1415
@ViewChild('accordionContent') elementView: ElementRef;
1516

16-
expanded: boolean = false;
1717
viewHeight: number;
1818

1919
constructor(public renderer: Renderer) { }
2020

2121
ngAfterViewInit() {
2222
this.viewHeight = this.elementView.nativeElement.offsetHeight;
23-
this.renderer.setElementStyle(this.elementView.nativeElement, 'height', 0 + 'px');
23+
24+
if (!this.expanded) {
25+
this.renderer.setElementStyle(this.elementView.nativeElement, 'height', 0 + 'px');
26+
}
2427
}
2528

2629
toggleAccordion() {

src/pages/accordion-list/accordion-list.html

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,12 @@
1010
<ion-content padding>
1111
<p>Accordion list example - Best places to visit:</p>
1212

13-
<accordion-list *ngFor="let item of items"
13+
<accordion-list *ngFor="let item of items; let index = index"
1414
[title]="item.name"
1515
textColor="#FFF"
1616
hasMargin="false"
17-
headerColor="#F53D3D">
17+
headerColor="#F53D3D"
18+
[expanded]="index === 0">
1819
<img [src]="item.imageUrl">
1920
<p text-wrap>{{item.description}}</p>
2021
</accordion-list>

0 commit comments

Comments
 (0)