Skip to content

Commit

Permalink
feat(accordion): add custom css class at the card level (#3563)
Browse files Browse the repository at this point in the history
Fixes #2262
  • Loading branch information
gpolychronis committed Feb 13, 2020
1 parent a18f6bd commit 8ea21bf
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
15 changes: 15 additions & 0 deletions src/accordion/accordion.spec.ts
Expand Up @@ -493,6 +493,21 @@ describe('ngb-accordion', () => {
expect(headingLinks[0].disabled).toBeTruthy();
});

it('should have the custom class', () => {
const testHtml = `
<ngb-accordion #acc="ngbAccordion">
<ngb-panel *ngFor="let panel of panels" [id]="panel.id" [cardClass]="'custom-class' + panel.id"></ngb-panel>
</ngb-accordion>
`;
const fixture = createTestComponent(testHtml);
const cards = <HTMLDivElement[]>Array.from(fixture.nativeElement.querySelectorAll('.card'));

fixture.detectChanges();
expect(cards[0]).toHaveCssClass('custom-classone');
expect(cards[1]).toHaveCssClass('custom-classtwo');
expect(cards[2]).toHaveCssClass('custom-classthree');
});

it('should remove collapsed panels content from DOM', () => {
const fixture = TestBed.createComponent(TestComponent);
fixture.detectChanges();
Expand Down
7 changes: 6 additions & 1 deletion src/accordion/accordion.ts
Expand Up @@ -97,6 +97,11 @@ export class NgbPanel implements AfterContentChecked {
*/
@Input() type: string;

/**
* An optional class applied to the card that wraps the panel.
*/
@Input() cardClass: string;

titleTpl: NgbPanelTitle | null;
headerTpl: NgbPanelHeader | null;
contentTpl: NgbPanelContent | null;
Expand Down Expand Up @@ -156,7 +161,7 @@ export interface NgbPanelChangeEvent {
</button>
</ng-template>
<ng-template ngFor let-panel [ngForOf]="panels">
<div class="card">
<div [class]="'card ' + panel.cardClass || ''">
<div role="tab" id="{{panel.id}}-header" [class]="'card-header ' + (panel.type ? 'bg-'+panel.type: type ? 'bg-'+type : '')">
<ng-template [ngTemplateOutlet]="panel.headerTpl?.templateRef || t"
[ngTemplateOutletContext]="{$implicit: panel, opened: panel.isOpen}"></ng-template>
Expand Down

0 comments on commit 8ea21bf

Please sign in to comment.