Skip to content

Commit 282fbb4

Browse files
authored
fix: add allowDragFromClosest to make .slick-cell or child draggable (#897)
* fix: regression with RowMoveManager, row could no longer be moved * fix: add `allowDragFromClosest` to make any .`slick-cell` draggable
1 parent 02226bd commit 282fbb4

File tree

3 files changed

+7
-2
lines changed

3 files changed

+7
-2
lines changed

src/models/interactions.interface.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,12 @@ export interface DraggableOption {
88
/** container DOM element, defaults to "document" */
99
containerElement?: HTMLElement | Document;
1010

11-
/** when defined, only allow dragging from an element that matches a specific query selector */
11+
/** when defined, will allow dragging from a specific element by using the .matches() query selector. */
1212
allowDragFrom?: string;
1313

14+
/** when defined, will allow dragging from a specific element or its closest parent by using the .closest() query selector. */
15+
allowDragFromClosest?: string;
16+
1417
/** drag initialized callback */
1518
onDragInit?: Function;
1619

src/slick.grid.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -819,6 +819,7 @@ export class SlickGrid<TData = any, C extends Column<TData> = Column<TData>, O e
819819
this.slickDraggableInstance = Draggable({
820820
containerElement: this._container,
821821
allowDragFrom: 'div.slick-cell',
822+
allowDragFromClosest: 'div.slick-cell',
822823
onDragInit: this.handleDragInit.bind(this),
823824
onDragStart: this.handleDragStart.bind(this),
824825
onDrag: this.handleDrag.bind(this),

src/slick.interactions.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ const Utils = IIFE_ONLY ? Slick.Utils : Utils_;
1919
* available optional options:
2020
* - containerElement: container DOM element, defaults to "document"
2121
* - allowDragFrom: when defined, only allow dragging from an element that matches a specific query selector
22+
* - allowDragFromClosest: when defined, only allow dragging from an element or its parent matching a specific .closest() query selector
2223
* - onDragInit: drag initialized callback
2324
* - onDragStart: drag started callback
2425
* - onDrag: drag callback
@@ -67,7 +68,7 @@ export function Draggable(options: DraggableOption) {
6768
const targetEvent: MouseEvent | Touch = (event as TouchEvent)?.touches?.[0] ?? event;
6869
const { target } = targetEvent;
6970

70-
if (!options.allowDragFrom || (options.allowDragFrom && element.matches(options.allowDragFrom))) {
71+
if (!options.allowDragFrom || (options.allowDragFrom && (element.matches(options.allowDragFrom)) || (options.allowDragFromClosest && element.closest(options.allowDragFromClosest)))) {
7172
originaldd.dragHandle = element as HTMLElement;
7273
const winScrollPos = Utils.windowScrollPosition();
7374
startX = winScrollPos.left + targetEvent.clientX;

0 commit comments

Comments
 (0)