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

expand only one panel when SingleBranchExpand is set to true #10465

Merged
merged 5 commits into from
Nov 16, 2021
Merged
Show file tree
Hide file tree
Changes from 2 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
Expand Up @@ -104,6 +104,7 @@ describe('Rendering Tests', () => {

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

accordion.panels[0].expand();
accordion.panels[1].expand();
tick();
fix.detectChanges();
Expand Down
27 changes: 22 additions & 5 deletions projects/igniteui-angular/src/lib/accordion/accordion.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ export class IgxAccordionComponent implements AfterContentInit, AfterViewInit, O
private _panels!: QueryList<IgxExpansionPanelComponent>;
private _animationSettings!: ToggleAnimationSettings;
private _expandedPanels!: Set<IgxExpansionPanelComponent>;
private _expandingPanels!: Set<IgxExpansionPanelComponent>;
private _destroy$ = new Subject<void>();
private _unsubChildren$ = new Subject<void>();
private _enabledPanels!: IgxExpansionPanelComponent[];
Expand All @@ -210,6 +211,7 @@ export class IgxAccordionComponent implements AfterContentInit, AfterViewInit, O
/** @hidden @internal **/
public ngAfterViewInit(): void {
this._expandedPanels = new Set<IgxExpansionPanelComponent>(this._panels.filter(panel => !panel.collapsed));
this._expandingPanels = new Set<IgxExpansionPanelComponent>();
this._panels.changes.pipe(takeUntil(this._destroy$)).subscribe(() => {
this.subToChanges();
});
Expand Down Expand Up @@ -320,28 +322,43 @@ 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);
});
panel.contentExpanding.pipe(takeUntil(this._unsubChildren$)).subscribe((args: IExpansionPanelCancelableEventArgs) => {
if (args.cancel) {
return;
}
const evArgs: IAccordionCancelableEventArgs = { ...args, owner: this, panel: args.owner };
this.panelExpanding.emit(evArgs);
if (evArgs.cancel) {
args.cancel = true;
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);
});
Expand Down