Skip to content

Commit d5d5fc9

Browse files
committed
feat(cdk/drag-drop): support configurable propagation of mousedown and touchstart events.
Allows exposing native mousedown and touchstart events to parent elements so that listeners farther up the chain can respond before a CdkDragEvent has started. Without these events, certain gestures (swiper, etc) cannot be achieved when events are started on a DragRef element. Fixes: #19333
1 parent 8125651 commit d5d5fc9

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

src/cdk/drag-drop/directives/drag.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ export class CdkDrag<T = any> implements AfterViewInit, OnChanges, OnDestroy {
199199
config.dragStartThreshold : 5,
200200
pointerDirectionChangeThreshold: config && config.pointerDirectionChangeThreshold != null ?
201201
config.pointerDirectionChangeThreshold : 5,
202+
propagateEvents: config && config.propagateEvents,
202203
zIndex: config?.zIndex
203204
});
204205
this._dragRef.data = this;

src/cdk/drag-drop/drag-drop.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ import {DragDropRegistry} from './drag-drop-registry';
1616
/** Default configuration to be used when creating a `DragRef`. */
1717
const DEFAULT_CONFIG = {
1818
dragStartThreshold: 5,
19-
pointerDirectionChangeThreshold: 5
19+
pointerDirectionChangeThreshold: 5,
20+
propagateEvents: false
2021
};
2122

2223
/**

src/cdk/drag-drop/drag-ref.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,13 @@ export interface DragRefConfig {
3333
*/
3434
pointerDirectionChangeThreshold: number;
3535

36+
/**
37+
* Whether touch/mouse begin events should propagate to
38+
* parent elements in the DOM when CDK initiates a drag
39+
* sequence.
40+
*/
41+
propagateEvents: boolean;
42+
3643
/** `z-index` for the absolutely-positioned elements that are created by the drag item. */
3744
zIndex?: number;
3845
}
@@ -744,7 +751,9 @@ export class DragRef<T = any> {
744751
// Always stop propagation for the event that initializes
745752
// the dragging sequence, in order to prevent it from potentially
746753
// starting another sequence for a draggable parent somewhere up the DOM tree.
747-
event.stopPropagation();
754+
if (!this._config.propagateEvents) {
755+
event.stopPropagation();
756+
}
748757

749758
const isDragging = this.isDragging();
750759
const isTouchSequence = isTouchEvent(event);

0 commit comments

Comments
 (0)