Skip to content

Commit 8c2044c

Browse files
committed
refactor(accordion): deprecate prop open in favour of visible
1 parent 146e6b5 commit 8c2044c

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

projects/coreui-angular/src/lib/accordion/accordion-item/accordion-item.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<div class="accordion-header">
33
<ng-container *ngTemplateOutlet="templates?.accordionHeaderTemplate || defaultAccordionHeaderTemplate; context: itemContext"></ng-container>
44
</div>
5-
<div class="accordion-collapse" cCollapse [visible]="open" [attr.aria-expanded]="open" [id]="contentId">
5+
<div class="accordion-collapse" cCollapse [visible]="visible" [attr.aria-expanded]="open" [id]="contentId">
66
<ng-container *ngTemplateOutlet="templates?.accordionBodyTemplate || defaultAccordionBodyTemplate; context: itemContext"></ng-container>
77
</div>
88
</ng-container>

projects/coreui-angular/src/lib/accordion/accordion-item/accordion-item.component.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,13 @@ export class AccordionItemComponent implements OnInit, OnDestroy, AfterContentIn
2323
/**
2424
* Toggle an accordion item programmatically
2525
* @type boolean
26+
* @default false
2627
*/
27-
@Input() open = false;
28+
@Input() visible: boolean = false;
29+
@Input() set open(value: boolean) {
30+
console.warn('c-accordion-item "open" prop is deprecated, use "visible" prop instead.')
31+
this.visible = value ?? false;
32+
}
2833

2934
@HostBinding('class')
3035
get hostClasses(): any {
@@ -33,7 +38,7 @@ export class AccordionItemComponent implements OnInit, OnDestroy, AfterContentIn
3338
};
3439
}
3540
contentId = `accordion-item-${nextId++}`;
36-
itemContext = { $implicit: this.open };
41+
itemContext = { $implicit: this.visible };
3742
templates: any = {};
3843

3944
@ContentChildren(TemplateIdDirective, {descendants: true}) contentTemplates!: QueryList<TemplateIdDirective>;

projects/coreui-angular/src/lib/accordion/accordion.service.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@ export class AccordionService {
2121
}
2222

2323
toggelItem(item: AccordionItemComponent): void {
24-
item.open = !item.open;
24+
item.visible = !item.visible;
2525
this.closeOtherItems(item);
2626
}
2727

2828
closeOtherItems(openItem: AccordionItemComponent): void {
2929
if (!this.alwaysOpen) {
3030
this.items.forEach((item: AccordionItemComponent) => {
3131
if (item !== openItem) {
32-
item.open = false;
32+
item.visible = false;
3333
}
3434
});
3535
}

0 commit comments

Comments
 (0)