diff --git a/projects/igniteui-angular/src/lib/grids/grid/column-resizing.spec.ts b/projects/igniteui-angular/src/lib/grids/grid/column-resizing.spec.ts index 6059ab22da9..b58b5f02b41 100644 --- a/projects/igniteui-angular/src/lib/grids/grid/column-resizing.spec.ts +++ b/projects/igniteui-angular/src/lib/grids/grid/column-resizing.spec.ts @@ -16,6 +16,7 @@ import { IgxAvatarComponent } from '../../avatar/avatar.component'; import { IColumnResizeEventArgs, IgxColumnComponent } from '../public_api'; import { Size } from "../common/enums"; import { setElementSize } from '../../test-utils/helper-utils.spec'; +import { IgxColumnResizerDirective } from '../resizing/resizer.directive'; describe('IgxGrid - Deferred Column Resizing #grid', () => { @@ -133,6 +134,27 @@ describe('IgxGrid - Deferred Column Resizing #grid', () => { expect(grid.columnList.get(1).width).toEqual('70px'); })); + it('should calculate correctly resizer position and column width when grid is scaled and zoomed', fakeAsync(() => { + grid.nativeElement.style.transform = 'scale(1.2)'; + grid.nativeElement.style.setProperty('zoom', '1.05'); + fixture.detectChanges(); + headerResArea = GridFunctions.getHeaderResizeArea(headers[1]).nativeElement; + UIInteractions.simulateMouseEvent('mousedown', headerResArea, 153, 0); + tick(200); + fixture.detectChanges(); + + const resizer = GridFunctions.getResizer(fixture); + const resizerDirective = resizer.componentInstance.resizer as IgxColumnResizerDirective; + const leftSetterSpy = spyOnProperty(resizerDirective, 'left', 'set').and.callThrough(); + UIInteractions.simulateMouseEvent('mousemove', resizer.nativeElement, 200, 5); + UIInteractions.simulateMouseEvent('mouseup', resizer.nativeElement, 200, 5); + fixture.detectChanges(); + + expect(leftSetterSpy).toHaveBeenCalled(); + expect(parseInt(leftSetterSpy.calls.mostRecent().args[0].toFixed(0))).toEqual(200); + expect(parseInt(grid.columnList.get(1).headerCell.nativeElement.getBoundingClientRect().width.toFixed(0))).toEqual(173); + })); + it('should be able to resize column to the minWidth < defaultMinWidth', fakeAsync(() => { const column = grid.getColumnByName('ID'); column.minWidth = 'a'; diff --git a/projects/igniteui-angular/src/lib/grids/resizing/resizer.component.html b/projects/igniteui-angular/src/lib/grids/resizing/resizer.component.html index 807f9b505ad..7da534bda24 100644 --- a/projects/igniteui-angular/src/lib/grids/resizing/resizer.component.html +++ b/projects/igniteui-angular/src/lib/grids/resizing/resizer.component.html @@ -4,5 +4,5 @@ [restrictHResizeMax]="colResizingService.restrictResizeMax" [restrictHResizeMin]="colResizingService.restrictResizeMin" [restrictResizerTop]="restrictResizerTop" - (resizeEnd)="colResizingService.resizeColumn($event)"> + (resizeEnd)="colResizingService.resizeColumn($event, resizer.ratio)"> diff --git a/projects/igniteui-angular/src/lib/grids/resizing/resizer.directive.ts b/projects/igniteui-angular/src/lib/grids/resizing/resizer.directive.ts index 83b51c07298..9bf213f801e 100644 --- a/projects/igniteui-angular/src/lib/grids/resizing/resizer.directive.ts +++ b/projects/igniteui-angular/src/lib/grids/resizing/resizer.directive.ts @@ -41,8 +41,13 @@ export class IgxColumnResizerDirective implements OnInit, OnDestroy { @Output() public resize = new Subject(); private _left: number; + private _ratio: number = 1; private _destroy = new Subject(); + public get ratio(): number { + return this._ratio; + } + constructor( public element: ElementRef, @Inject(DOCUMENT) public document, @@ -56,7 +61,7 @@ export class IgxColumnResizerDirective implements OnInit, OnDestroy { .pipe( takeUntil(this._destroy), takeUntil(this.resizeEnd), - map((event) => event.clientX - offset), + map((event) => (event.clientX - offset) / (this._ratio)), )) ) .subscribe((pos) => { @@ -113,8 +118,12 @@ export class IgxColumnResizerDirective implements OnInit, OnDestroy { public onMousedown(event: MouseEvent) { event.preventDefault(); const parent = this.element.nativeElement.parentElement.parentElement; - - this.left = this._left = event.clientX - parent.getBoundingClientRect().left; + const parentRectWidth = parent.getBoundingClientRect().width; + const parentComputedWidth = parseFloat(window.getComputedStyle(parent).width); + if (Math.abs(parentRectWidth - parentComputedWidth) > 1) { + this._ratio = parentRectWidth / parentComputedWidth; + } + this.left = this._left = (event.clientX - parent.getBoundingClientRect().left) / this._ratio; this.top = (event.target as HTMLElement).getBoundingClientRect().top - parent.getBoundingClientRect().top; this.resizeStart.next(event); diff --git a/projects/igniteui-angular/src/lib/grids/resizing/resizing.service.ts b/projects/igniteui-angular/src/lib/grids/resizing/resizing.service.ts index 2b6beae7418..b4106c80ede 100644 --- a/projects/igniteui-angular/src/lib/grids/resizing/resizing.service.ts +++ b/projects/igniteui-angular/src/lib/grids/resizing/resizing.service.ts @@ -35,7 +35,7 @@ export class IgxColumnResizingService { * @hidden */ public getColumnHeaderRenderedWidth() { - return this.column.headerCell.nativeElement.getBoundingClientRect().width; + return parseFloat(window.getComputedStyle(this.column.headerCell.nativeElement).width); } /** @@ -101,9 +101,9 @@ export class IgxColumnResizingService { /** * Resizes the column regaridng to the column minWidth and maxWidth. */ - public resizeColumn(event: MouseEvent) { + public resizeColumn(event: MouseEvent, ratio: number = 1) { this.showResizer = false; - const diff = event.clientX - this.startResizePos; + const diff = (event.clientX - this.startResizePos) / ratio; const colWidth = this.column.width; const isPercentageWidth = colWidth && typeof colWidth === 'string' && colWidth.indexOf('%') !== -1;