Skip to content

fix(igxSplitter): Assign pane props after zone is stable. #15800

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

Merged
merged 10 commits into from
Jun 27, 2025
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Component, HostBinding, Input, ElementRef, Output, EventEmitter, booleanAttribute } from '@angular/core';
import { Component, HostBinding, Input, ElementRef, Output, EventEmitter, booleanAttribute, signal } from '@angular/core';

/**
* Represents individual resizable/collapsible panes.
Expand All @@ -22,6 +22,7 @@ import { Component, HostBinding, Input, ElementRef, Output, EventEmitter, boolea
export class IgxSplitterPaneComponent {
private _minSize: string;
private _maxSize: string;
private _order = signal<number | null>(null);

/**
* @hidden @internal
Expand Down Expand Up @@ -102,7 +103,12 @@ export class IgxSplitterPaneComponent {

/** @hidden @internal */
@HostBinding('style.order')
public order!: number;
public get order() {
return this._order();
}
public set order(val) {
this._order.set(val)
}

/**
* @hidden @internal
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ describe('IgxSplitter', () => {
const secondPane = splitter.panes.toArray()[1].element;
expect(firstPane.textContent.trim()).toBe('Pane 1');
expect(secondPane.textContent.trim()).toBe('Pane 2');

fixture.detectChanges();
const splitterBar = fixture.debugElement.query(By.css(SPLITTERBAR_CLASS)).nativeElement;
expect(firstPane.style.order).toBe('0');
expect(splitterBar.style.order).toBe('1');
Expand Down Expand Up @@ -322,6 +322,13 @@ describe('IgxSplitter', () => {

expect(splitterBarComponent.style.transform).not.toBe('translate3d(0px, 0px, 0px)');
});

it('should render correctly panes created dynamically using @for', () => {
fixture = TestBed.createComponent(SplitterForOfPanesComponent);
fixture.detectChanges();
splitter = fixture.componentInstance.splitter;
expect(splitter.panes.length).toBe(3);
});
});

describe('IgxSplitter pane toggle', () => {
Expand All @@ -336,6 +343,7 @@ describe('IgxSplitter pane toggle', () => {
fixture = TestBed.createComponent(SplitterTogglePaneComponent);
fixture.detectChanges();
splitter = fixture.componentInstance.splitter;
fixture.detectChanges();
}));

it('should collapse/expand panes', () => {
Expand Down Expand Up @@ -601,3 +609,19 @@ export class SplitterTogglePaneComponent extends SplitterTestComponent {
})
export class SplitterCollapsedPaneComponent extends SplitterTestComponent {
}

@Component({
template: `
<igx-splitter>
@for (number of numbers; track number) {
<igx-splitter-pane>
<p>{{ number }}</p>
</igx-splitter-pane>
}
</igx-splitter>
`,
imports: [IgxSplitterComponent, IgxSplitterPaneComponent]
})
export class SplitterForOfPanesComponent extends SplitterTestComponent {
public numbers = [1, 2, 3];
}
15 changes: 9 additions & 6 deletions projects/igniteui-angular/src/lib/splitter/splitter.component.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { DOCUMENT } from '@angular/common';
import { AfterContentInit, Component, ContentChildren, ElementRef, EventEmitter, HostBinding, HostListener, Inject, Input, Output, QueryList, booleanAttribute, forwardRef } from '@angular/core';
import { AfterContentInit, Component, ContentChildren, ElementRef, EventEmitter, HostBinding, HostListener, Inject, Input, NgZone, Output, QueryList, booleanAttribute, forwardRef } from '@angular/core';
import { DragDirection, IDragMoveEventArgs, IDragStartEventArgs, IgxDragDirective, IgxDragIgnoreDirective } from '../directives/drag-drop/drag-drop.directive';
import { IgxSplitterPaneComponent } from './splitter-pane/splitter-pane.component';
import { take } from 'rxjs';

/**
* An enumeration that defines the `SplitterComponent` panes orientation.
Expand Down Expand Up @@ -155,7 +156,7 @@ export class IgxSplitterComponent implements AfterContentInit {
*/
private sibling!: IgxSplitterPaneComponent;

constructor(@Inject(DOCUMENT) public document, private elementRef: ElementRef) { }
constructor(@Inject(DOCUMENT) public document, private elementRef: ElementRef, private zone: NgZone) { }
/**
* Gets/Sets the splitter orientation.
*
Expand Down Expand Up @@ -198,7 +199,9 @@ export class IgxSplitterComponent implements AfterContentInit {

/** @hidden @internal */
public ngAfterContentInit(): void {
this.initPanes();
this.zone.onStable.pipe(take(1)).subscribe(() => {
this.initPanes();
});
this.panes.changes.subscribe(() => {
this.initPanes();
});
Expand Down Expand Up @@ -473,7 +476,7 @@ export class IgxSplitBarComponent {
* @hidden @internal
*/
public get prevButtonHidden() {
return this.siblings[0].collapsed && !this.siblings[1].collapsed;
return this.siblings[0]?.collapsed && !this.siblings[1]?.collapsed;
}

/**
Expand Down Expand Up @@ -560,7 +563,7 @@ export class IgxSplitBarComponent {
* @hidden @internal
*/
public get nextButtonHidden() {
return this.siblings[1].collapsed && !this.siblings[0].collapsed;
return this.siblings[1]?.collapsed && !this.siblings[0]?.collapsed;
}

/**
Expand Down Expand Up @@ -600,7 +603,7 @@ export class IgxSplitBarComponent {

protected get resizeDisallowed() {
const relatedTabs = this.siblings;
return !!relatedTabs.find(x => x.resizable === false || x.collapsed === true);
return !!relatedTabs.find(x => x?.resizable === false || x?.collapsed === true);
}

/**
Expand Down
Loading