Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/cdk/drag-drop/directives/drag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,10 @@ export class CdkDrag<T = any> implements AfterViewInit, OnChanges, OnDestroy {
/** Class to be added to the preview element. */
@Input('cdkDragPreviewClass') previewClass: string | string[];

/** Whether parent of drag container is fixed. */
@Input('cdkDropIsDragParentFixed')
dragParentFixed: boolean;

/** Emits when the user starts dragging the item. */
@Output('cdkDragStarted') started: EventEmitter<CdkDragStart> = new EventEmitter<CdkDragStart>();

Expand Down Expand Up @@ -372,6 +376,7 @@ export class CdkDrag<T = any> implements AfterViewInit, OnChanges, OnDestroy {
dragStartDelay : coerceNumberProperty(dragStartDelay);
ref.constrainPosition = this.constrainPosition;
ref.previewClass = this.previewClass;
ref.dragParentFixed = coerceBooleanProperty(this.dragParentFixed);
ref
.withBoundaryElement(this._getBoundaryElement())
.withPlaceholderTemplate(placeholder)
Expand Down
18 changes: 14 additions & 4 deletions src/cdk/drag-drop/drag-ref.ts
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,12 @@ export class DragRef<T = any> {
*/
constrainPosition?: (point: Point, dragRef: DragRef) => Point;

/**
* Whether drag container is placed in
* dialog or other element that has a fixed position.
*/
dragParentFixed: boolean = false;

constructor(
element: ElementRef<HTMLElement> | HTMLElement,
private _config: DragRefConfig,
Expand Down Expand Up @@ -1004,8 +1010,12 @@ export class DragRef<T = any> {
const handleElement = referenceElement === this._rootElement ? null : referenceElement;
const referenceRect = handleElement ? handleElement.getBoundingClientRect() : elementRect;
const point = isTouchEvent(event) ? event.targetTouches[0] : event;
const x = point.pageX - referenceRect.left - this._scrollPosition.left;
const y = point.pageY - referenceRect.top - this._scrollPosition.top;
const x = this.dragParentFixed ?
point.pageX - referenceRect.left :
point.pageX - referenceRect.left - this._scrollPosition.left;
const y = this.dragParentFixed ?
point.pageY - referenceRect.top :
point.pageY - referenceRect.top - this._scrollPosition.top;

return {
x: referenceRect.left - elementRect.left + x,
Expand All @@ -1019,8 +1029,8 @@ export class DragRef<T = any> {
const point = isTouchEvent(event) ? (event.touches[0] || event.changedTouches[0]) : event;

return {
x: point.pageX - this._scrollPosition.left,
y: point.pageY - this._scrollPosition.top
x: this.dragParentFixed ? point.pageX : point.pageX - this._scrollPosition.left,
y: this.dragParentFixed ? point.pageY : point.pageY - this._scrollPosition.top
};
}

Expand Down