Skip to content

Commit 6bde537

Browse files
Ivan KitanovIvan Kitanov
authored andcommitted
fix(splitter): Sizing panes corectly with minSize and the browser is shrinked
1 parent 77e08bc commit 6bde537

File tree

2 files changed

+81
-3
lines changed

2 files changed

+81
-3
lines changed

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

Lines changed: 71 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,76 @@ 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+
}
534+
465535
@Component({
466536
template: `
467537
<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
@@ -177,7 +177,7 @@ export class IgxSplitterComponent implements AfterContentInit {
177177
/**
178178
* Sets the visibility of the handle and expanders in the splitter bar.
179179
* False by default
180-
*
180+
*
181181
* @example
182182
* ```html
183183
* <igx-splitter [nonCollapsible]='true'>
@@ -239,7 +239,15 @@ export class IgxSplitterComponent implements AfterContentInit {
239239
}
240240

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

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

0 commit comments

Comments
 (0)