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

Sizing panes corectly with minSize and the browser is shrienked #15423

Open
wants to merge 2 commits into
base: 19.0.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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 @@ -21,7 +21,7 @@ describe('IgxSplitter', () => {
}).compileComponents()));
let fixture: ComponentFixture<SplitterTestComponent>;
let splitter: IgxSplitterComponent;

beforeEach(waitForAsync(() => {
fixture = TestBed.createComponent(SplitterTestComponent);
fixture.detectChanges();
Expand Down Expand Up @@ -462,6 +462,74 @@ describe('IgxSplitter pane collapse', () => {
});
});

describe('IgxSplitter resizing with minSize and browser window is shrinked', () => {
configureTestSuite();
beforeAll(waitForAsync(() => TestBed.configureTestingModule({
imports: [
SplitterMinSiezComponent
]
}).compileComponents()));

let fixture; let splitter;
beforeEach(waitForAsync(() => {
fixture = TestBed.createComponent(SplitterMinSiezComponent);
fixture.detectChanges();
splitter = fixture.componentInstance.splitter;
}));

it('should set the correct sizes when the user drags one pane to the end of another', () => {
const pane1 = splitter.panes.toArray()[0];
const pane2 = splitter.panes.toArray()[1];
const splitterBarComponent = fixture.debugElement.query(By.css(SPLITTERBAR_CLASS)).context;
const minSize = parseInt(pane1.minSize);
spyOn(splitter, 'onMoveEnd').and.callThrough();

pane1.size = (splitter.getTotalSize() - parseInt(pane2.size)) + 'px';
fixture.detectChanges();

splitterBarComponent.moveStart.emit(pane1);
fixture.detectChanges();
splitterBarComponent.movingEnd.emit(splitter.getTotalSize() -minSize);
fixture.detectChanges();

splitter.elementRef.nativeElement.style.width = '500px';
pane2.size = (splitter.getTotalSize() - minSize) + 'px';
fixture.detectChanges();

splitterBarComponent.moveStart.emit(pane1);
fixture.detectChanges();
splitterBarComponent.movingEnd.emit(-400);
fixture.detectChanges();

const isFullSize = pane1.size === '100%' || pane1.size === (splitter.getTotalSize() + 'px');

expect(splitter.onMoveEnd).toHaveBeenCalled();
expect(isFullSize).toBeTruthy();
});
});

@Component({
template: `
<igx-splitter>
<igx-splitter-pane minSize="200px">
<div>
Pane 1
</div>
</igx-splitter-pane>
<igx-splitter-pane size="200px">
<div>
Pane 2
</div>
</igx-splitter-pane>
</igx-splitter>
`,
imports: [IgxSplitterComponent, IgxSplitterPaneComponent]
})
export class SplitterMinSiezComponent {
@ViewChild(IgxSplitterComponent, { static: true })
public splitter: IgxSplitterComponent;
}

@Component({
template: `
<igx-splitter [type]="type">
Expand Down
12 changes: 10 additions & 2 deletions projects/igniteui-angular/src/lib/splitter/splitter.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ export class IgxSplitterComponent implements AfterContentInit {
/**
* Sets the visibility of the handle and expanders in the splitter bar.
* False by default
*
*
* @example
* ```html
* <igx-splitter [nonCollapsible]='true'>
Expand Down Expand Up @@ -239,7 +239,15 @@ export class IgxSplitterComponent implements AfterContentInit {
}

public onMoveEnd(delta: number) {
const [ paneSize, siblingSize ] = this.calcNewSizes(delta);
let [ paneSize, siblingSize ] = this.calcNewSizes(delta);

if (paneSize + siblingSize > this.getTotalSize() && delta < 0) {
paneSize = this.getTotalSize();
siblingSize = 0;
} else if(paneSize + siblingSize > this.getTotalSize() && delta > 0) {
paneSize = 0;
siblingSize = this.getTotalSize();
}

if (this.pane.isPercentageSize) {
// handle % resizes
Expand Down
Loading