Opened 14 months ago

Last modified 14 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 14 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 14 months ago by scottgonzalez

  • Summary changed from Setting containment in start works only the second time to Draggable: Allow setting containment in the start event
  • Type changed from bug to feature

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 14 months ago by scottgonzalez

  • Status changed from new to open
  • Summary changed from Draggable: Allow setting containment in the start event to Draggable: 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.