Skip to content

Commit eeb980f

Browse files
Merge pull request #16122 from IgniteUI/aahmedov/fix-resizer-incorrect-position-in-shadow-dom-master
Fix column resizer position - master
2 parents 3e65c73 + 5100788 commit eeb980f

File tree

3 files changed

+83
-8
lines changed

3 files changed

+83
-8
lines changed

projects/igniteui-angular/src/lib/grids/grid/column-resizing.spec.ts

Lines changed: 72 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { MultiColumnHeadersComponent } from '../../test-utils/grid-samples.spec'
1111
import { GridFunctions } from '../../test-utils/grid-functions.spec';
1212
import { IgxCellHeaderTemplateDirective, IgxCellTemplateDirective } from '../columns/templates.directive';
1313
import { IgxAvatarComponent } from '../../avatar/avatar.component';
14-
import { IColumnResizeEventArgs, IgxColumnComponent } from '../public_api';
14+
import { IColumnResizeEventArgs, IgxColumnComponent, IgxGridToolbarComponent, IgxGridToolbarTitleComponent } from '../public_api';
1515
import { Size } from "../common/enums";
1616
import { setElementSize } from '../../test-utils/helper-utils.spec';
1717
import { IgxColumnResizerDirective } from '../resizing/resizer.directive';
@@ -903,6 +903,65 @@ describe('IgxGrid - Deferred Column Resizing #grid', () => {
903903
expect(firstRowCells.length).toEqual(11);
904904
}));
905905
});
906+
907+
describe('Resizer tests: ', () => {
908+
let fixture: ComponentFixture<any>;
909+
let grid: IgxGridComponent;
910+
911+
beforeEach(fakeAsync(() => {
912+
fixture = TestBed.createComponent(ResizableColumnsWithToolbarComponent);
913+
fixture.detectChanges();
914+
grid = fixture.componentInstance.grid;
915+
}));
916+
917+
it('should align the resizer top with the grid header top', fakeAsync(() => {
918+
grid.nativeElement.style.marginTop = '40px';
919+
fixture.detectChanges();
920+
const headers = GridFunctions.getColumnHeaders(fixture);
921+
const headerResArea = GridFunctions.getHeaderResizeArea(headers[0]).nativeElement;
922+
923+
const headerRectTop = headerResArea.getBoundingClientRect().top;
924+
925+
UIInteractions.simulateMouseEvent('mousedown', headerResArea, 100, 15);
926+
tick(200);
927+
fixture.detectChanges();
928+
929+
const resizer = GridFunctions.getResizer(fixture).nativeElement;
930+
expect(resizer).toBeDefined();
931+
932+
const resizerRectTop = resizer.getBoundingClientRect().top;
933+
UIInteractions.simulateMouseEvent('mousemove', resizer, 250, 15);
934+
UIInteractions.simulateMouseEvent('mouseup', resizer, 250, 15);
935+
fixture.detectChanges();
936+
937+
938+
expect(Math.abs(resizerRectTop - headerRectTop)).toBeLessThanOrEqual(1);
939+
}));
940+
941+
it('should align the resizer top with the grid header top when grid is scaled', fakeAsync(() => {
942+
grid.nativeElement.style.transform = 'scale(0.6)';
943+
fixture.detectChanges();
944+
945+
const headers = GridFunctions.getColumnHeaders(fixture);
946+
const headerResArea = GridFunctions.getHeaderResizeArea(headers[1]).nativeElement;
947+
const headerRectTop = headerResArea.getBoundingClientRect().top;
948+
949+
// Trigger resize to show resizer
950+
UIInteractions.simulateMouseEvent('mousedown', headerResArea, 153, 0);
951+
tick(200);
952+
fixture.detectChanges();
953+
954+
const resizer = GridFunctions.getResizer(fixture).nativeElement;
955+
expect(resizer).toBeDefined();
956+
957+
const resizerRectTop = resizer.getBoundingClientRect().top;
958+
959+
UIInteractions.simulateMouseEvent('mouseup', resizer, 200, 5);
960+
fixture.detectChanges();
961+
962+
expect(Math.abs(resizerRectTop - headerRectTop)).toBeLessThanOrEqual(1);
963+
}));
964+
});
906965
});
907966

908967
@Component({
@@ -915,6 +974,18 @@ export class ResizableColumnsComponent {
915974
public data = SampleTestData.personIDNameRegionData();
916975
}
917976

977+
@Component({
978+
template: GridTemplateStrings.declareGrid(`width="500px" height="300px"`, ``,
979+
'<igx-grid-toolbar><igx-grid-toolbar-title>Grid Toolbar</igx-grid-toolbar-title></igx-grid-toolbar>' +
980+
ColumnDefinitions.resizableThreeOfFour),
981+
imports: [IgxGridComponent, IgxColumnComponent, IgxGridToolbarComponent, IgxGridToolbarTitleComponent]
982+
})
983+
export class ResizableColumnsWithToolbarComponent {
984+
@ViewChild(IgxGridComponent, { static: true }) public grid: IgxGridComponent;
985+
986+
public data = SampleTestData.personIDNameRegionData();
987+
}
988+
918989
@Component({
919990
template: GridTemplateStrings.declareGrid(`width="618px" height="600px"`, ``, `<igx-column [field]="'Released'" [pinned]="true" width="100px" dataType="boolean" [resizable]="true"></igx-column>
920991
<igx-column [field]="'ReleaseDate'" [pinned]="true" width="100px" dataType="date" [resizable]="true"

projects/igniteui-angular/src/lib/grids/resizing/resize-handle.directive.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
OnDestroy
99
} from '@angular/core';
1010
import { Subject, fromEvent } from 'rxjs';
11-
import { debounceTime, takeUntil } from 'rxjs/operators';
11+
import { debounceTime, map, takeUntil } from 'rxjs/operators';
1212
import { ColumnType } from '../common/grid.interface';
1313
import { IgxColumnResizingService } from './resizing.service';
1414

@@ -69,19 +69,23 @@ export class IgxResizeHandleDirective implements AfterViewInit, OnDestroy {
6969
public ngAfterViewInit() {
7070
if (!this.column.columnGroup && this.column.resizable) {
7171
this.zone.runOutsideAngular(() => {
72-
fromEvent(this.element.nativeElement, 'mousedown').pipe(
72+
fromEvent<MouseEvent>(this.element.nativeElement, 'mousedown').pipe(
73+
map((event) => ({
74+
event,
75+
// Preserves the original 'event.target' in a shadow DOM context.
76+
target: event.target as HTMLElement
77+
})),
7378
debounceTime(this.DEBOUNCE_TIME),
7479
takeUntil(this.destroy$)
75-
).subscribe((event: MouseEvent) => {
76-
80+
).subscribe(({ event, target }: { event: MouseEvent; target: HTMLElement }) => {
7781
if (this._dblClick) {
7882
this._dblClick = false;
7983
return;
8084
}
8185

8286
if (event.button === 0) {
8387
this._onResizeAreaMouseDown(event);
84-
this.column.grid.resizeLine.resizer.onMousedown(event);
88+
this.column.grid.resizeLine.resizer.onMousedown(event, target);
8589
}
8690
});
8791
});

projects/igniteui-angular/src/lib/grids/resizing/resizer.directive.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ export class IgxColumnResizerDirective implements OnInit, OnDestroy {
115115
this.resizeEnd.complete();
116116
}
117117

118-
public onMousedown(event: MouseEvent) {
118+
public onMousedown(event: MouseEvent, resizeHandleTarget: HTMLElement) {
119119
event.preventDefault();
120120
const parent = this.element.nativeElement.parentElement.parentElement;
121121
const parentRectWidth = parent.getBoundingClientRect().width;
@@ -124,7 +124,7 @@ export class IgxColumnResizerDirective implements OnInit, OnDestroy {
124124
this._ratio = parentRectWidth / parentComputedWidth;
125125
}
126126
this.left = this._left = (event.clientX - parent.getBoundingClientRect().left) / this._ratio;
127-
this.top = (event.target as HTMLElement).getBoundingClientRect().top - parent.getBoundingClientRect().top;
127+
this.top = (resizeHandleTarget.getBoundingClientRect().top - parent.getBoundingClientRect().top) / this._ratio;
128128

129129
this.resizeStart.next(event);
130130
}

0 commit comments

Comments
 (0)