Opened 15 months ago

Last modified 15 months ago

#14912 open feature

Draggable: Allow setting containment during drag

Reported by: Mrten Owned by:
Priority: minor Milestone: none
Component: ui.draggable Version: 1.11.4
Keywords: Cc:
Blocked by: Blocking:

Description

If you set a containment in the start event instead of in the default options, like this:

https://jsfiddle.net/8wzdt8z5/8/

the intended containment between cell 2 and 4 only works the second time you drag cell 3.

If you add an (obvious internal) call to _setContainment it works the first time (see fiddle).

Change History (3)

comment:1 Changed 15 months ago by Mrten

An obvious fix for this is:

Index: draggable.js
===================================================================
--- draggable.js	(revision 29006)
+++ draggable.js	(working copy)
@@ -202,15 +202,15 @@
 		//Adjust the mouse offset relative to the helper if "cursorAt" is supplied
 		(o.cursorAt && this._adjustOffsetFromHelper(o.cursorAt));

-		//Set a containment if given in the options
-		this._setContainment();
-
 		//Trigger event + callbacks
 		if (this._trigger("start", event) === false) {
 			this._clear();
 			return false;
 		}

+		//Set a containment if given in the options
+		this._setContainment();
+
 		//Recache the helper size
 		this._cacheHelperProportions();

comment:2 Changed 15 months ago by Scott González

Summary: Setting containment in start works only the second timeDraggable: Allow setting containment in the start event
Type: bugfeature

It's not that this works the second time, it's that the call from the first time has been applied.

This option is not meant to be updated during a drag. I'm not sure if we want to add support for this either. We'll have to discuss this within the team.

In the meantime, you can accomplish this with a custom containment via the drag event. See https://jsfiddle.net/8wzdt8z5/9/

comment:3 Changed 15 months ago by Scott González

Status: newopen
Summary: Draggable: Allow setting containment in the start eventDraggable: Allow setting containment during drag

We're tentatively accepting this feature for the rewrite. However, the proposed patch is too limited since it only supports one specific time that the option can be changed. A proper implementation would handle changes to containment at any point.

Note: See TracTickets for help on using tickets.