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: added accordion component #89

Open
wants to merge 3 commits into
base: angular-19
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<cdk-accordion class="block max-w-[500px]">
@for (item of items; track item; let index = $index) {
<cdk-accordion-item #accordionItem="cdkAccordionItem"
class="block border border-gray-300 first:rounded-t-lg last:rounded-b-lg">
<button
class="flex items-center justify-between w-full bg-none border-none p-4 text-left hover:cursor-pointer hover:bg-gray-200"
(click)="accordionItem.toggle()" tabindex="0" [attr.id]="'accordion-header-' + index"
[attr.aria-expanded]="accordionItem.expanded" [attr.aria-controls]="'accordion-body-' + index">
{{ item.title }}
<span class="text-sm text-gray-600">
<em [class.indicon-chevron_up]="!accordionItem.expanded"
[class.indicon-chevron_down]="accordionItem.expanded"></em>
</span>
</button>
@if(accordionItem.expanded) {
<div class="p-4" role="region" [style.display]="accordionItem.expanded ? '' : 'none'"
[attr.id]="'accordion-body-' + index" [attr.aria-labelledby]="'accordion-header-' + index" [innerHTML]="item.description">
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please get rid of innerHTML and use angular content projection like in modal.component

</div>
}
</cdk-accordion-item>
}
</cdk-accordion>
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { Component } from '@angular/core';
import {CdkAccordionModule} from '@angular/cdk/accordion';

@Component({
selector: 'app-accordion',
imports: [CdkAccordionModule],
templateUrl: './accordion.component.html'
})
export class AccordionComponent {
items = [{title: 'Item 1', description: '<table><thead><tr><th>Header 1</th><th>Header 2</th><th>Header 3</th></tr></thead><tbody><tr><td>Data 1</td><td>Data 2</td><td>Data 3</td></tr></tbody></table>'},
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to put items here. As this is single accordion component, we can rely only on title as angular input here and content which will be passed to this accordion.

{title: 'Item 2', description: '<div class="text-lg text-gray-600">Description</div>'}
];
expandedIndex = 0;
}