|
9 | 9 | ViewEncapsulation,
|
10 | 10 | signal,
|
11 | 11 | } from '@angular/core';
|
| 12 | +import {NgTemplateOutlet} from '@angular/common'; |
12 | 13 | import {fakeAsync, flush, tick} from '@angular/core/testing';
|
13 | 14 | import {
|
14 | 15 | dispatchEvent,
|
@@ -1631,6 +1632,25 @@ describe('Standalone CdkDrag', () => {
|
1631 | 1632 | .toBe('translate3d(50px, 100px, 0px)');
|
1632 | 1633 | }));
|
1633 | 1634 |
|
| 1635 | + it('should be able to drag with a handle that is defined in a separate embedded view', fakeAsync(() => { |
| 1636 | + const fixture = createComponent(StandaloneDraggableWithExternalTemplateHandle); |
| 1637 | + fixture.detectChanges(); |
| 1638 | + const dragElement = fixture.componentInstance.dragElement.nativeElement; |
| 1639 | + const handle = fixture.nativeElement.querySelector('.handle'); |
| 1640 | + |
| 1641 | + expect(dragElement.style.transform).toBeFalsy(); |
| 1642 | + dragElementViaMouse(fixture, dragElement, 50, 100); |
| 1643 | + |
| 1644 | + expect(dragElement.style.transform) |
| 1645 | + .withContext('Expected not to be able to drag the element by itself.') |
| 1646 | + .toBeFalsy(); |
| 1647 | + |
| 1648 | + dragElementViaMouse(fixture, handle, 50, 100); |
| 1649 | + expect(dragElement.style.transform) |
| 1650 | + .withContext('Expected to drag the element by its handle.') |
| 1651 | + .toBe('translate3d(50px, 100px, 0px)'); |
| 1652 | + })); |
| 1653 | + |
1634 | 1654 | it('should disable the tap highlight while dragging via the handle', fakeAsync(() => {
|
1635 | 1655 | // This test is irrelevant if the browser doesn't support styling the tap highlight color.
|
1636 | 1656 | if (!('webkitTapHighlightColor' in document.body.style)) {
|
@@ -2010,3 +2030,21 @@ class DraggableNgContainerWithAlternateRoot {
|
2010 | 2030 | class PlainStandaloneDraggable {
|
2011 | 2031 | @ViewChild(CdkDrag) dragInstance: CdkDrag;
|
2012 | 2032 | }
|
| 2033 | + |
| 2034 | +@Component({ |
| 2035 | + template: ` |
| 2036 | + <div #dragElement cdkDrag |
| 2037 | + style="width: 100px; height: 100px; background: red; position: relative"> |
| 2038 | + <ng-container [ngTemplateOutlet]="template"/> |
| 2039 | + </div> |
| 2040 | +
|
| 2041 | + <ng-template #template> |
| 2042 | + <div cdkDragHandle class="handle" style="width: 10px; height: 10px; background: green;"></div> |
| 2043 | + </ng-template> |
| 2044 | + `, |
| 2045 | + standalone: true, |
| 2046 | + imports: [CdkDrag, CdkDragHandle, NgTemplateOutlet], |
| 2047 | +}) |
| 2048 | +class StandaloneDraggableWithExternalTemplateHandle { |
| 2049 | + @ViewChild('dragElement') dragElement: ElementRef<HTMLElement>; |
| 2050 | +} |
0 commit comments