Skip to content

Commit

Permalink
fix(accordion): don't crash for panels with no content
Browse files Browse the repository at this point in the history
Fixes #2250

Closes #2251
  • Loading branch information
pkozlowski-opensource committed Mar 27, 2018
1 parent 3b3c979 commit da96dec
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
14 changes: 14 additions & 0 deletions src/accordion/accordion.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,20 @@ describe('ngb-accordion', () => {
expect(childTitle).not.toContain('parent title');
});

it('should not crash for an empty accordion', () => {
const fixture = createTestComponent('<ngb-accordion></ngb-accordion>');
expect(getPanels(fixture.nativeElement).length).toBe(0);
});

it('should not crash for panels without content', () => {
const fixture =
createTestComponent('<ngb-accordion activeIds="open_me"><ngb-panel id="open_me"></ngb-panel></ngb-accordion>');
const panelsContent = getPanelsContent(fixture.nativeElement);

expect(panelsContent.length).toBe(1);
expect(panelsContent[0].textContent.trim()).toBe('');
});

it('should have the appropriate content', () => {
const fixture = TestBed.createComponent(TestComponent);
fixture.detectChanges();
Expand Down
2 changes: 1 addition & 1 deletion src/accordion/accordion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ export interface NgbPanelChangeEvent {
</div>
<div id="{{panel.id}}" role="tabpanel" [attr.aria-labelledby]="panel.id + '-header'"
class="card-body collapse {{panel.isOpen ? 'show' : null}}" *ngIf="!destroyOnHide || panel.isOpen">
<ng-template [ngTemplateOutlet]="panel.contentTpl.templateRef"></ng-template>
<ng-template [ngTemplateOutlet]="panel.contentTpl?.templateRef"></ng-template>
</div>
</div>
</ng-template>
Expand Down

0 comments on commit da96dec

Please sign in to comment.