Skip to content

Commit 9864b18

Browse files
Ivan KitanovIvan Kitanov
authored andcommitted
fix(splitter): Sizing panes corectly with minSize and the browser is shrinked
1 parent 212f811 commit 9864b18

File tree

2 files changed

+80
-3
lines changed

2 files changed

+80
-3
lines changed

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

Lines changed: 70 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ describe('IgxSplitter', () => {
2121
}).compileComponents()));
2222
let fixture: ComponentFixture<SplitterTestComponent>;
2323
let splitter: IgxSplitterComponent;
24-
24+
2525
beforeEach(waitForAsync(() => {
2626
fixture = TestBed.createComponent(SplitterTestComponent);
2727
fixture.detectChanges();
@@ -462,6 +462,75 @@ describe('IgxSplitter pane collapse', () => {
462462
});
463463
});
464464

465+
describe('IgxSplitter resizing with minSize and browser window is shrinked', () => {
466+
configureTestSuite();
467+
beforeAll(waitForAsync(() => TestBed.configureTestingModule({
468+
imports: [
469+
SplitterMinSiezComponent
470+
]
471+
}).compileComponents()));
472+
473+
let fixture; let splitter;
474+
beforeEach(waitForAsync(() => {
475+
fixture = TestBed.createComponent(SplitterMinSiezComponent);
476+
fixture.detectChanges();
477+
splitter = fixture.componentInstance.splitter;
478+
}));
479+
480+
it('should set the correct sizes when the user drags one pane to the end of another', () => {
481+
const pane1 = splitter.panes.toArray()[0];
482+
const pane2 = splitter.panes.toArray()[1];
483+
const splitterBarComponent = fixture.debugElement.query(By.css(SPLITTERBAR_CLASS)).context;
484+
const minSize = parseInt(pane1.minSize);
485+
spyOn(splitter, 'onMoveEnd').and.callThrough();
486+
487+
pane1.size = (splitter.getTotalSize() - parseInt(pane2.size)) + 'px';
488+
fixture.detectChanges();
489+
490+
splitterBarComponent.moveStart.emit(pane1);
491+
fixture.detectChanges();
492+
splitterBarComponent.movingEnd.emit(splitter.getTotalSize() -minSize);
493+
fixture.detectChanges();
494+
495+
spyOnProperty(window, 'innerWidth', 'get').and.returnValue(500);
496+
window.dispatchEvent(new Event('resize'));
497+
splitter.elementRef.nativeElement.style.width = '500px';
498+
pane2.size = (splitter.getTotalSize() - minSize) + 'px';
499+
fixture.detectChanges();
500+
501+
splitterBarComponent.moveStart.emit(pane1);
502+
fixture.detectChanges();
503+
splitterBarComponent.movingEnd.emit(-400);
504+
fixture.detectChanges();
505+
506+
const isFullSize = pane1.size === '100%' || pane1.size === (splitter.getTotalSize() + 'px');
507+
508+
expect(splitter.onMoveEnd).toHaveBeenCalled();
509+
expect(isFullSize).toBeTruthy();
510+
});
511+
});
512+
513+
@Component({
514+
template: `
515+
<igx-splitter>
516+
<igx-splitter-pane minSize="200px">
517+
<div>
518+
Pane 1
519+
</div>
520+
</igx-splitter-pane>
521+
<igx-splitter-pane size="200px">
522+
<div>
523+
Pane 2
524+
</div>
525+
</igx-splitter-pane>
526+
</igx-splitter>
527+
`,
528+
imports: [IgxSplitterComponent, IgxSplitterPaneComponent]
529+
})
530+
export class SplitterMinSiezComponent {
531+
@ViewChild(IgxSplitterComponent, { static: true })
532+
public splitter: IgxSplitterComponent;
533+
}
465534
@Component({
466535
template: `
467536
<igx-splitter [type]="type">

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ export class IgxSplitterComponent implements AfterContentInit {
178178
/**
179179
* Sets the visibility of the handle and expanders in the splitter bar.
180180
* False by default
181-
*
181+
*
182182
* @example
183183
* ```html
184184
* <igx-splitter [nonCollapsible]='true'>
@@ -240,7 +240,15 @@ export class IgxSplitterComponent implements AfterContentInit {
240240
}
241241

242242
public onMoveEnd(delta: number) {
243-
const [ paneSize, siblingSize ] = this.calcNewSizes(delta);
243+
let [ paneSize, siblingSize ] = this.calcNewSizes(delta);
244+
245+
if (paneSize + siblingSize > this.getTotalSize() && delta < 0) {
246+
paneSize = this.getTotalSize();
247+
siblingSize = 0;
248+
} else if(paneSize + siblingSize > this.getTotalSize() && delta > 0) {
249+
paneSize = 0;
250+
siblingSize = this.getTotalSize();
251+
}
244252

245253
if (this.pane.isPercentageSize) {
246254
// handle % resizes

0 commit comments

Comments
 (0)