Skip to content

Commit 200c513

Browse files
skrustevSvetoslav Krastevdkamburov
authored
enhancement(moving): Move pointerDown and pointerMove logic to avoid needing additional custom attributes. (#12966)
* enhancement(moving): Move pointerDown and pointerMove logic to avoid needing additional custom attributes. Fix drag directive eating up event for children. * enhancement(moving): Ensure on pointer down group drop area is show and headers cannot be dragged from sorting/filtering icons. * fix(drag): Ensure that target telement is present in dom when setting pointer capture. * chore(*): Cleanup imports. * enhancement(moving): Retain `draggable` attribute as an option and add changelog. * chore(*): Fix typo in changelog. * fix(moving): Revert back uses of draggable attributes to be sure all is working as expected. * chore(*): Update changelog with grouping behavior change. * chore(*): Move pointerdown handling in corresponding methods. --------- Co-authored-by: Svetoslav Krastev <[email protected]> Co-authored-by: Deyan Kamburov <[email protected]>
1 parent aef549d commit 200c513

14 files changed

+77
-48
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ All notable changes for each version of this project will be documented in this
77
### General
88
- `IgxStepper`:
99
- **Breaking Change** The `IgxStepSubTitleDirective` has been renamed to `IgxStepSubtitleDirective`. Automatic migrations are available and will be applied on `ng update`.
10+
- `IgxGrid`, `IgxTreeGrid`, `IgxHierarchicalGrid`
11+
- The `draggable` attribute is no longer required to be set on interactable elements, if a column header is templated and the Column Moving is enabled in order for handlers for any event to be triggered. Now `draggable='false'` can be used as an addition if the user shouldn't be able to drag a column by that element, but even if omitted `click` events for example will trigger now.
12+
- **Behavioral Change** When there are already grouped columns, the group drop area now shows after dragging of a column starts and not when only click actions are performed.
1013

1114
## 16.0.0
1215

projects/igniteui-angular/src/lib/directives/drag-drop/drag-drop.directive.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -915,19 +915,21 @@ export class IgxDragDirective implements AfterContentInit, OnDestroy {
915915
return;
916916
}
917917

918-
this._clicked = true;
919-
this._pointerDownId = event.pointerId;
920-
921918
// Set pointer capture so we detect pointermove even if mouse is out of bounds until ghostElement is created.
922919
const handleFound = this.dragHandles.find(handle => handle.element.nativeElement === event.target);
923-
const targetElement = handleFound ? handleFound.element.nativeElement : this.element.nativeElement;
924-
if (this.pointerEventsEnabled) {
920+
const targetElement = handleFound ? handleFound.element.nativeElement : event.target || this.element.nativeElement;
921+
const targetValid = document.body.contains(targetElement);
922+
if (this.pointerEventsEnabled && targetValid) {
923+
this._pointerDownId = event.pointerId;
925924
targetElement.setPointerCapture(this._pointerDownId);
926-
} else {
925+
} else if (targetValid) {
927926
targetElement.focus();
928927
event.preventDefault();
928+
} else {
929+
return;
929930
}
930931

932+
this._clicked = true;
931933
if (this.pointerEventsEnabled || !this.touchEventsEnabled) {
932934
// Check first for pointer events or non touch, because we can have pointer events and touch events at once.
933935
this._startX = event.pageX;

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -417,10 +417,12 @@ describe('IgxGrid - Column Moving #grid', () => {
417417
await wait();
418418

419419
// step 2 - verify columnMovingStart is fired correctly
420-
expect(fixture.componentInstance.countStart).toEqual(1);
421-
expect(fixture.componentInstance.source).toEqual(grid.columns[0]);
422420
UIInteractions.simulatePointerEvent('pointermove', header, 156, 71);
423421
await wait(50);
422+
423+
expect(fixture.componentInstance.countStart).toEqual(1);
424+
expect(fixture.componentInstance.source).toEqual(grid.columns[0]);
425+
424426
UIInteractions.simulatePointerEvent('pointermove', header, 330, 75);
425427
await wait(50);
426428

@@ -447,12 +449,13 @@ describe('IgxGrid - Column Moving #grid', () => {
447449
UIInteractions.simulatePointerEvent('pointerdown', header, 150, 65);
448450
await wait();
449451

452+
UIInteractions.simulatePointerEvent('pointermove', header, 156, 71);
453+
await wait();
454+
450455
if (fixture.componentInstance.source.field === 'ID') {
451456
fixture.componentInstance.cancel = true;
452457
}
453458

454-
UIInteractions.simulatePointerEvent('pointermove', header, 156, 71);
455-
await wait();
456459
UIInteractions.simulatePointerEvent('pointermove', header, 330, 75);
457460
await wait(50);
458461
UIInteractions.simulatePointerEvent('pointerup', header, 330, 75);

projects/igniteui-angular/src/lib/grids/headers/grid-header-group.component.html

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@
2828
</ng-template>
2929

3030
<ng-template #defaultCollapseIndicator>
31-
<igx-icon [attr.draggable]="false" >
32-
{{column.expanded ? 'expand_more' : 'chevron_right'}} </igx-icon>
31+
<igx-icon>{{column.expanded ? 'expand_more' : 'chevron_right'}} </igx-icon>
3332
</ng-template>
3433

3534
<ng-container *ngIf="!grid.hasColumnLayouts && column.columnGroup">
@@ -56,7 +55,7 @@
5655
(pointerleave)="onPointerLeave()"
5756
>
5857
<ng-container *ngIf="column.collapsible">
59-
<div class="igx-grid-th__expander" (click)="toggleExpandState($event)">
58+
<div class="igx-grid-th__expander" (pointerdown)="onPointerDownIndicator($event)" (click)="toggleExpandState($event)">
6059
<ng-container
6160
*ngTemplateOutlet="column.collapsibleIndicatorTemplate ? column.collapsibleIndicatorTemplate : defaultCollapseIndicator; context: {$implicit: column, column: column}">
6261
</ng-container>

projects/igniteui-angular/src/lib/grids/headers/grid-header-group.component.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,14 @@ export class IgxGridHeaderGroupComponent implements DoCheck {
289289
}
290290
}
291291

292+
/**
293+
* @hidden @internal
294+
*/
295+
public onPointerDownIndicator(event) {
296+
// Stop propagation of pointer events to now allow column dragging using the header indicators.
297+
event.stopPropagation();
298+
}
299+
292300
/**
293301
* @hidden @internal
294302
*/

projects/igniteui-angular/src/lib/grids/headers/grid-header.component.html

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,12 @@
2020
<ng-container *ngIf="column.sortable && !disabled">
2121
<div class="sort-icon"
2222
[attr.data-sortIndex]="(grid.sortingOptions.mode === 'single' && grid.sortingExpressions.length <=1) ? null : column.field | sortingIndex:grid.sortingExpressions"
23-
[attr.draggable]="false" (click)="onSortingIconClick($event)" (pointerdown)="$event.stopPropagation()">
23+
(pointerdown)="onPointerDownIndicator($event)" (click)="onSortingIconClick($event)">
2424
<ng-container *ngTemplateOutlet="sortIconTemplate; context: { $implicit: this }"></ng-container>
2525
</div>
2626
</ng-container>
2727
<ng-container *ngIf="grid.allowFiltering && column.filterable && grid.filterMode === 'excelStyleFilter'">
28-
<div [ngClass]="filterIconClassName" (click)="onFilteringIconClick($event)"
29-
(pointerdown)="$event.stopPropagation()">
28+
<div [ngClass]="filterIconClassName" (pointerdown)="onPointerDownIndicator($event)" (click)="onFilteringIconClick($event)" >
3029
<ng-container *ngTemplateOutlet="esfIconTemplate; context: { $implicit: this }"></ng-container>
3130
</div>
3231
</ng-container>

projects/igniteui-angular/src/lib/grids/headers/grid-header.component.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,22 +247,41 @@ export class IgxGridHeaderComponent implements DoCheck, OnDestroy {
247247
this.column.applySelectableClass = false;
248248
}
249249

250+
/**
251+
* @hidden @internal
252+
*/
250253
public ngDoCheck() {
251254
this.getSortDirection();
252255
this.cdr.markForCheck();
253256
}
254257

258+
/**
259+
* @hidden @internal
260+
*/
255261
public ngOnDestroy(): void {
256262
this._destroy$.next(true);
257263
this._destroy$.complete();
258264
}
259265

266+
/**
267+
* @hidden @internal
268+
*/
269+
public onPointerDownIndicator(event) {
270+
// Stop propagation of pointer events to now allow column dragging using the header indicators.
271+
event.stopPropagation();
272+
}
260273

274+
/**
275+
* @hidden @internal
276+
*/
261277
public onFilteringIconClick(event) {
262278
event.stopPropagation();
263279
this.grid.filteringService.toggleFilterDropdown(this.nativeElement, this.column);
264280
}
265281

282+
/**
283+
* @hidden @internal
284+
*/
266285
public onSortingIconClick(event) {
267286
event.stopPropagation();
268287
this.triggerSort();

projects/igniteui-angular/src/lib/grids/moving/moving.drag.directive.ts

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ export class IgxColumnMovingDragDirective extends IgxDragDirective implements On
4242
_platformUtil: PlatformUtil,
4343
) {
4444
super(cdr, element, viewContainer, zone, renderer, _platformUtil);
45+
this.ghostClass = this._ghostClass;
4546
}
4647

4748
public override ngOnDestroy() {
@@ -59,32 +60,28 @@ export class IgxColumnMovingDragDirective extends IgxDragDirective implements On
5960
return;
6061
}
6162

62-
event.preventDefault();
63-
event.stopPropagation();
64-
65-
this._removeOnDestroy = false;
66-
this.cms.column = this.column;
67-
this.ghostClass = this._ghostClass;
68-
6963
super.onPointerDown(event);
70-
this.column.grid.cdr.detectChanges();
71-
72-
const args = {
73-
source: this.column
74-
};
75-
this.column.grid.columnMovingStart.emit(args);
76-
77-
this.subscription$ = fromEvent(this.column.grid.document.defaultView, 'keydown').subscribe((ev: KeyboardEvent) => {
78-
if (ev.key === this.platformUtil.KEYMAP.ESCAPE) {
79-
this.onEscape(ev);
80-
}
81-
});
8264
}
8365

8466
public override onPointerMove(event: Event) {
85-
event.preventDefault();
86-
super.onPointerMove(event);
67+
if (this._clicked && !this._dragStarted) {
68+
this._removeOnDestroy = false;
69+
this.cms.column = this.column;
70+
this.column.grid.cdr.detectChanges();
71+
72+
const movingStartArgs = {
73+
source: this.column
74+
};
75+
this.column.grid.columnMovingStart.emit(movingStartArgs);
76+
77+
this.subscription$ = fromEvent(this.column.grid.document.defaultView, 'keydown').subscribe((ev: KeyboardEvent) => {
78+
if (ev.key === this.platformUtil.KEYMAP.ESCAPE) {
79+
this.onEscape(ev);
80+
}
81+
});
82+
}
8783

84+
super.onPointerMove(event);
8885
if (this._dragStarted && this.ghostElement && !this.cms.column) {
8986
this.cms.column = this.column;
9087
this.column.grid.cdr.detectChanges();

projects/igniteui-angular/src/lib/grids/moving/moving.drop.directive.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,8 @@ export class IgxColumnMovingDropDirective extends IgxDropDirective implements On
158158
public override onDragDrop(event) {
159159
event.preventDefault();
160160
const drag = event.detail.owner;
161-
if (!(drag instanceof IgxColumnMovingDragDirective)) {
161+
if (this.cms.cancelDrop || !(drag instanceof IgxColumnMovingDragDirective)) {
162+
this.cms.cancelDrop = false;
162163
return;
163164
}
164165

projects/igniteui-angular/src/lib/grids/pivot-grid/pivot-row-dimension-content.component.html

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,15 @@
1313

1414
<ng-template #headerTemplate let-column>
1515
<div class='igx-grid__tr--header igx-grid__row-indentation--level-{{getLevel()}}'>
16-
<igx-icon [attr.draggable]=" false" (click)="toggleRowDimension($event)">
16+
<igx-icon [attr.draggable]="false" (click)="toggleRowDimension($event)">
1717
{{ getExpandState() ? 'expand_more' : 'chevron_right'}}</igx-icon>
1818
{{column.header}}
1919
</div>
2020
</ng-template>
2121

2222
<ng-template #headerDefaultTemplate let-column>
23-
2423
<div class='igx-grid__tr--header igx-grid__row-indentation--level-{{getLevel()}}'>
25-
<igx-icon style='flex-shrink: 0;' [attr.draggable]=" false">
24+
<igx-icon style='flex-shrink: 0;' [attr.draggable]="false">
2625
</igx-icon>
2726
{{column.header}}
2827
</div>

0 commit comments

Comments
 (0)