|
1 | | -import { Component, ViewChild, DebugElement, QueryList } from '@angular/core'; |
| 1 | +import { Component, ViewChild, DebugElement, QueryList, TemplateRef } from '@angular/core'; |
2 | 2 | import { TestBed, ComponentFixture, fakeAsync, tick } from '@angular/core/testing'; |
3 | 3 | import { FormsModule } from '@angular/forms'; |
4 | 4 | import { By } from '@angular/platform-browser'; |
@@ -450,6 +450,40 @@ describe('Row Drag Tests #grid', () => { |
450 | 450 | const ghostText = document.getElementsByClassName(CSS_CLASS_GHOST_ROW)[0].textContent; |
451 | 451 | expect(ghostText).toEqual(' Moving a row! '); |
452 | 452 | }); |
| 453 | + |
| 454 | + it('should allow setting custom drag icon and ghost element via Input.', () => { |
| 455 | + fixture = TestBed.createComponent(IgxGridRowCustomGhostDraggableComponent); |
| 456 | + grid = fixture.componentInstance.instance as IgxGridComponent; |
| 457 | + fixture.detectChanges(); |
| 458 | + dropAreaElement = fixture.debugElement.query(By.css(CSS_CLASS_DROPPABLE_AREA)).nativeElement; |
| 459 | + grid.dragIndicatorIconTemplate = fixture.componentInstance.rowDragTemplate; |
| 460 | + grid.dragGhostCustomTemplate = fixture.componentInstance.rowDragGhostTemplate; |
| 461 | + fixture.detectChanges(); |
| 462 | + rows = grid.rowList.toArray(); |
| 463 | + dragIndicatorElements = fixture.debugElement.queryAll(By.css(CSS_CLASS_DRAG_INDICATOR)); |
| 464 | + dragIndicatorElement = dragIndicatorElements[2].nativeElement; |
| 465 | + dragRows = fixture.debugElement.queryAll(By.directive(IgxRowDragDirective)); |
| 466 | + rowDragDirective = dragRows[1].injector.get(IgxRowDragDirective); |
| 467 | + |
| 468 | + expect(dragIndicatorElement.textContent.trim()).toBe('expand_less'); |
| 469 | + |
| 470 | + startPoint = UIInteractions.getPointFromElement(dragIndicatorElement); |
| 471 | + movePoint = UIInteractions.getPointFromElement(rows[4].nativeElement); |
| 472 | + dropPoint = UIInteractions.getPointFromElement(dropAreaElement); |
| 473 | + pointerDownEvent = UIInteractions.createPointerEvent('pointerdown', startPoint); |
| 474 | + pointerMoveEvent = UIInteractions.createPointerEvent('pointermove', movePoint); |
| 475 | + |
| 476 | + rowDragDirective.onPointerDown(pointerDownEvent); |
| 477 | + rowDragDirective.onPointerMove(pointerMoveEvent); |
| 478 | + pointerMoveEvent = UIInteractions.createPointerEvent('pointermove', dropPoint); |
| 479 | + rowDragDirective.onPointerMove(pointerMoveEvent); |
| 480 | + const ghostElements: HTMLCollection = document.getElementsByClassName(CSS_CLASS_GHOST_ROW); |
| 481 | + expect(ghostElements.length).toEqual(1); |
| 482 | + |
| 483 | + const ghostText = document.getElementsByClassName(CSS_CLASS_GHOST_ROW)[0].textContent; |
| 484 | + expect(ghostText.trim()).toEqual('CUSTOM'); |
| 485 | + |
| 486 | + }); |
453 | 487 | }); |
454 | 488 | }); |
455 | 489 |
|
@@ -1228,12 +1262,27 @@ export class IgxGridRowDraggableComponent extends DataParent { |
1228 | 1262 | <div #nonDroppableArea class="non-droppable-area" |
1229 | 1263 | [ngStyle]="{width:'100px', height:'100px', backgroundColor:'yellow'}"> |
1230 | 1264 | </div> |
| 1265 | +
|
| 1266 | + <ng-template #rowDragGhostTemplate let-data igxRowDragGhost> |
| 1267 | + <div class="dragGhost"> |
| 1268 | + CUSTOM |
| 1269 | + </div> |
| 1270 | + </ng-template> |
| 1271 | + <ng-template #rowDragTemplate let-data igxDragIndicatorIcon> |
| 1272 | + <igx-icon>expand_less</igx-icon> |
| 1273 | + </ng-template> |
1231 | 1274 | ` |
1232 | 1275 | }) |
1233 | 1276 | export class IgxGridRowCustomGhostDraggableComponent extends DataParent { |
1234 | 1277 | @ViewChild(IgxGridComponent, { read: IgxGridComponent, static: true }) |
1235 | 1278 | public instance: IgxGridComponent; |
1236 | 1279 |
|
| 1280 | + @ViewChild('rowDragGhostTemplate', {read: TemplateRef, static: true }) |
| 1281 | + public rowDragGhostTemplate: TemplateRef<any>; |
| 1282 | + |
| 1283 | + @ViewChild('rowDragTemplate', {read: TemplateRef, static: true }) |
| 1284 | + public rowDragTemplate: TemplateRef<any>; |
| 1285 | + |
1237 | 1286 | @ViewChild('dropArea', { read: IgxDropDirective, static: true }) |
1238 | 1287 | public dropArea: IgxDropDirective; |
1239 | 1288 |
|
|
0 commit comments