Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(accordion): add custom class on card level #3563

Merged
merged 1 commit into from Feb 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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