Skip to content

Commit df93331

Browse files
authored
Merge pull request #10465 from IgniteUI/mkirkova/fix-10242-master
expand only one panel when SingleBranchExpand is set to true
2 parents d380ced + 7c6e021 commit df93331

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

projects/igniteui-angular/src/lib/accordion/accordion.component.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ describe('Rendering Tests', () => {
104104

105105
expect(accordion.panelCollapsed.emit).toHaveBeenCalledTimes(3);
106106

107+
accordion.panels[0].expand();
107108
accordion.panels[1].expand();
108109
tick();
109110
fix.detectChanges();

projects/igniteui-angular/src/lib/accordion/accordion.component.ts

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@ export class IgxAccordionComponent implements AfterContentInit, AfterViewInit, O
196196
private _panels!: QueryList<IgxExpansionPanelComponent>;
197197
private _animationSettings!: ToggleAnimationSettings;
198198
private _expandedPanels!: Set<IgxExpansionPanelComponent>;
199+
private _expandingPanels!: Set<IgxExpansionPanelComponent>;
199200
private _destroy$ = new Subject<void>();
200201
private _unsubChildren$ = new Subject<void>();
201202
private _enabledPanels!: IgxExpansionPanelComponent[];
@@ -210,6 +211,7 @@ export class IgxAccordionComponent implements AfterContentInit, AfterViewInit, O
210211
/** @hidden @internal **/
211212
public ngAfterViewInit(): void {
212213
this._expandedPanels = new Set<IgxExpansionPanelComponent>(this._panels.filter(panel => !panel.collapsed));
214+
this._expandingPanels = new Set<IgxExpansionPanelComponent>();
213215
this._panels.changes.pipe(takeUntil(this._destroy$)).subscribe(() => {
214216
this.subToChanges();
215217
});
@@ -320,28 +322,43 @@ export class IgxAccordionComponent implements AfterContentInit, AfterViewInit, O
320322
this._panels.forEach(panel => {
321323
panel.contentExpanded.pipe(takeUntil(this._unsubChildren$)).subscribe((args: IExpansionPanelEventArgs) => {
322324
this._expandedPanels.add(args.owner);
325+
this._expandingPanels.delete(args.owner);
323326
const evArgs: IAccordionEventArgs = { ...args, owner: this, panel: args.owner };
324327
this.panelExpanded.emit(evArgs);
325328
});
326329
panel.contentExpanding.pipe(takeUntil(this._unsubChildren$)).subscribe((args: IExpansionPanelCancelableEventArgs) => {
327330
if (args.cancel) {
328331
return;
329332
}
333+
const evArgs: IAccordionCancelableEventArgs = { ...args, owner: this, panel: args.owner };
334+
this.panelExpanding.emit(evArgs);
335+
if (evArgs.cancel) {
336+
args.cancel = true;
337+
return;
338+
}
330339
if (this.singleBranchExpand) {
331340
this._expandedPanels.forEach(p => {
332341
if (!p.header.disabled) {
333342
p.collapse();
334343
}
335344
});
336-
}
337-
const evArgs: IAccordionCancelableEventArgs = { ...args, owner: this, panel: args.owner };
338-
this.panelExpanding.emit(evArgs);
339-
if (evArgs.cancel) {
340-
args.cancel = true;
345+
this._expandingPanels.forEach(p => {
346+
if (!p.header.disabled) {
347+
if (!p.animationSettings.closeAnimation) {
348+
p.openAnimationPlayer?.reset();
349+
}
350+
if (!p.animationSettings.openAnimation) {
351+
p.closeAnimationPlayer?.reset();
352+
}
353+
p.collapse();
354+
}
355+
});
356+
this._expandingPanels.add(args.owner);
341357
}
342358
});
343359
panel.contentCollapsed.pipe(takeUntil(this._unsubChildren$)).subscribe((args: IExpansionPanelEventArgs) => {
344360
this._expandedPanels.delete(args.owner);
361+
this._expandingPanels.delete(args.owner);
345362
const evArgs: IAccordionEventArgs = { ...args, owner: this, panel: args.owner };
346363
this.panelCollapsed.emit(evArgs);
347364
});

0 commit comments

Comments
 (0)