From 5af8d4e2c4c294bcccd915e4950cb0dddeed9c51 Mon Sep 17 00:00:00 2001 From: MonikaKirkova Date: Wed, 10 Nov 2021 13:24:47 +0200 Subject: [PATCH 1/2] fix(accordion): expand only one panel when SingleBranchExpand is true --- .../lib/accordion/accordion.component.spec.ts | 1 + .../src/lib/accordion/accordion.component.ts | 28 +++++++++++++++---- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/projects/igniteui-angular/src/lib/accordion/accordion.component.spec.ts b/projects/igniteui-angular/src/lib/accordion/accordion.component.spec.ts index c002d05e1ce..e89c0b5f81c 100644 --- a/projects/igniteui-angular/src/lib/accordion/accordion.component.spec.ts +++ b/projects/igniteui-angular/src/lib/accordion/accordion.component.spec.ts @@ -104,6 +104,7 @@ describe('Rendering Tests', () => { expect(accordion.panelCollapsed.emit).toHaveBeenCalledTimes(3); + accordion.panels[0].expand(); accordion.panels[1].expand(); tick(); fix.detectChanges(); diff --git a/projects/igniteui-angular/src/lib/accordion/accordion.component.ts b/projects/igniteui-angular/src/lib/accordion/accordion.component.ts index 9315317fab6..bcf4d682235 100644 --- a/projects/igniteui-angular/src/lib/accordion/accordion.component.ts +++ b/projects/igniteui-angular/src/lib/accordion/accordion.component.ts @@ -196,6 +196,7 @@ export class IgxAccordionComponent implements AfterContentInit, AfterViewInit, O private _panels!: QueryList; private _animationSettings!: ToggleAnimationSettings; private _expandedPanels!: Set; + private _expandingPanels!: Set; private _destroy$ = new Subject(); private _unsubChildren$ = new Subject(); private _enabledPanels!: IgxExpansionPanelComponent[]; @@ -210,6 +211,7 @@ export class IgxAccordionComponent implements AfterContentInit, AfterViewInit, O /** @hidden @internal **/ public ngAfterViewInit(): void { this._expandedPanels = new Set(this._panels.filter(panel => !panel.collapsed)); + this._expandingPanels = new Set(); this._panels.changes.pipe(takeUntil(this._destroy$)).subscribe(() => { this.subToChanges(); }); @@ -320,6 +322,7 @@ export class IgxAccordionComponent implements AfterContentInit, AfterViewInit, O this._panels.forEach(panel => { panel.contentExpanded.pipe(takeUntil(this._unsubChildren$)).subscribe((args: IExpansionPanelEventArgs) => { this._expandedPanels.add(args.owner); + this._expandingPanels.delete(args.owner); const evArgs: IAccordionEventArgs = { ...args, owner: this, panel: args.owner }; this.panelExpanded.emit(evArgs); }); @@ -327,21 +330,36 @@ export class IgxAccordionComponent implements AfterContentInit, AfterViewInit, O if (args.cancel) { return; } + const evArgs: IAccordionCancelableEventArgs = { ...args, owner: this, panel: args.owner }; + this.panelExpanding.emit(evArgs); + if (evArgs.cancel) { + args.cancel = true; + this._expandedPanels.delete(args.owner); + return; + } if (this.singleBranchExpand) { this._expandedPanels.forEach(p => { if (!p.header.disabled) { p.collapse(); } }); - } - const evArgs: IAccordionCancelableEventArgs = { ...args, owner: this, panel: args.owner }; - this.panelExpanding.emit(evArgs); - if (evArgs.cancel) { - args.cancel = true; + this._expandingPanels.forEach(p => { + if (!p.header.disabled) { + if (!p.animationSettings.closeAnimation) { + p.openAnimationPlayer?.reset(); + } + if (!p.animationSettings.openAnimation) { + p.closeAnimationPlayer?.reset(); + } + p.collapse(); + } + }); + this._expandingPanels.add(args.owner); } }); panel.contentCollapsed.pipe(takeUntil(this._unsubChildren$)).subscribe((args: IExpansionPanelEventArgs) => { this._expandedPanels.delete(args.owner); + this._expandingPanels.delete(args.owner); const evArgs: IAccordionEventArgs = { ...args, owner: this, panel: args.owner }; this.panelCollapsed.emit(evArgs); }); From 5d7cb040e6aa7c10e615f9e1a08aa8ad7af4da09 Mon Sep 17 00:00:00 2001 From: MonikaKirkova Date: Fri, 12 Nov 2021 17:02:25 +0200 Subject: [PATCH 2/2] refactor(accordion): add requested change --- .../igniteui-angular/src/lib/accordion/accordion.component.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/projects/igniteui-angular/src/lib/accordion/accordion.component.ts b/projects/igniteui-angular/src/lib/accordion/accordion.component.ts index bcf4d682235..f66dc3b49ab 100644 --- a/projects/igniteui-angular/src/lib/accordion/accordion.component.ts +++ b/projects/igniteui-angular/src/lib/accordion/accordion.component.ts @@ -334,7 +334,6 @@ export class IgxAccordionComponent implements AfterContentInit, AfterViewInit, O this.panelExpanding.emit(evArgs); if (evArgs.cancel) { args.cancel = true; - this._expandedPanels.delete(args.owner); return; } if (this.singleBranchExpand) {