Skip to content

Commit f13f648

Browse files
IvanKitanov17Ivan KitanovkdinevkacheshmarovaChronosSF
authored
Sizing panes corectly with minSize and when the browser is shrinked (#15421)
* fix(splitter): Sizing panes corectly with minSize and the browser is shrinked * fix(tests): providing bg locale for date-util test spec --------- Co-authored-by: Ivan Kitanov <IKitanov@infragistics.com> Co-authored-by: Konstantin Dinev <kdinev@mail.bw.edu> Co-authored-by: Vasya Kacheshmarova <vasq1989@gmail.com> Co-authored-by: Stamen Stoychev <sstoychev@infragistics.com>
1 parent 3e3b3fe commit f13f648

File tree

3 files changed

+84
-2
lines changed

3 files changed

+84
-2
lines changed

projects/igniteui-angular/src/lib/date-common/util/date-time.util.spec.ts

+6
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
11
import { DateTimeUtil } from './date-time.util';
22
import { DatePart, DatePartInfo } from '../../directives/date-time-editor/date-time-editor.common';
33
import { DataType } from '../../data-operations/data-util';
4+
import localeBg from "@angular/common/locales/bg";
5+
import { registerLocaleData } from '@angular/common';
6+
47

58
const reduceToDictionary = (parts: DatePartInfo[]) => parts.reduce((obj, x) => {
69
obj[x.type] = x;
710
return obj;
811
}, {});
912

1013
describe(`DateTimeUtil Unit tests`, () => {
14+
15+
registerLocaleData(localeBg);
16+
1117
describe('Date Time Parsing', () => {
1218
it('should correctly parse all date time parts (base)', () => {
1319
let result = DateTimeUtil.parseDateTimeFormat('dd/MM/yyyy HH:mm:ss:SS a');

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

+69-1
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,74 @@ 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+
splitter.elementRef.nativeElement.style.width = '500px';
496+
pane2.size = (splitter.getTotalSize() - minSize) + 'px';
497+
fixture.detectChanges();
498+
499+
splitterBarComponent.moveStart.emit(pane1);
500+
fixture.detectChanges();
501+
splitterBarComponent.movingEnd.emit(-400);
502+
fixture.detectChanges();
503+
504+
const isFullSize = pane1.size === '100%' || pane1.size === (splitter.getTotalSize() + 'px');
505+
506+
expect(splitter.onMoveEnd).toHaveBeenCalled();
507+
expect(isFullSize).toBeTruthy();
508+
});
509+
});
510+
511+
@Component({
512+
template: `
513+
<igx-splitter>
514+
<igx-splitter-pane minSize="200px">
515+
<div>
516+
Pane 1
517+
</div>
518+
</igx-splitter-pane>
519+
<igx-splitter-pane size="200px">
520+
<div>
521+
Pane 2
522+
</div>
523+
</igx-splitter-pane>
524+
</igx-splitter>
525+
`,
526+
imports: [IgxSplitterComponent, IgxSplitterPaneComponent]
527+
})
528+
export class SplitterMinSiezComponent {
529+
@ViewChild(IgxSplitterComponent, { static: true })
530+
public splitter: IgxSplitterComponent;
531+
}
532+
465533
@Component({
466534
template: `
467535
<igx-splitter [type]="type">

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

+9-1
Original file line numberDiff line numberDiff line change
@@ -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)