Skip to content

Commit 7c5578a

Browse files
Possibility to set accordion's initial state as expanded.
1 parent 0b88cb0 commit 7c5578a

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

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

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

1416
@ViewChild('accordionContent') elementView: ElementRef;
1517

16-
expanded: boolean = false;
1718
viewHeight: number;
1819

1920
constructor(public renderer: Renderer) { }
20-
21+
2122
ngAfterViewInit() {
23+
this.handleInitialState();
2224
this.viewHeight = this.elementView.nativeElement.offsetHeight;
23-
this.renderer.setElementStyle(this.elementView.nativeElement, 'height', 0 + 'px');
25+
console.log(this.expanded);
26+
if(!this.expanded)
27+
this.renderer.setElementStyle(this.elementView.nativeElement, 'height', 0 + 'px');
2428
}
2529

2630
toggleAccordion() {
@@ -29,4 +33,8 @@ export class AccordionListComponent {
2933
this.renderer.setElementStyle(this.elementView.nativeElement, 'height', newHeight);
3034
}
3135

36+
handleInitialState(){
37+
this.expanded = this.initialState === 'expanded'
38+
}
39+
3240
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
[title]="item.name"
1515
textColor="#FFF"
1616
hasMargin="false"
17-
headerColor="#F53D3D">
17+
headerColor="#F53D3D"
18+
initialState="expanded">
1819
<img [src]="item.imageUrl">
1920
<p text-wrap>{{item.description}}</p>
2021
</accordion-list>

0 commit comments

Comments
 (0)