Opened 3 years ago

Closed 3 years ago

Last modified 3 years ago

#9733 closed bug (fixed)

Draggable: Changing containment option doesn't work

Reported by: benth Owned by: benth
Priority: minor Milestone: 1.11.0
Component: ui.draggable Version: 1.10.3
Keywords: Cc:
Blocked by: Blocking:

Description

If containment is such that relative_container is set, and then containment changes e.g. to 'window', the old relative_container will remain instead of being unset.

Change History (9)

comment:1 Changed 3 years ago by scottgonzalez

  • Owner set to benth
  • Status changed from new to pending

Please provide a reduced test case showing the problem. Describe what you're doing, not the internal code.

comment:2 follow-up: Changed 3 years ago by benth

  • Status changed from pending to new

I have a draggable element that had its containment set to another DOM element, but later would get set to 'window'. After that, if I was scrolled down the page, and started dragging the element, the element would skip up. I found that relative_container was set to the old containment.

relative_container is only set in _setContainer, at the end, but there are many code paths in _setContainer that return early. I fixed my problem by setting relative_container to null for all these paths.

You'll have to wait for a test case.

comment:3 in reply to: ↑ 2 Changed 3 years ago by tj.vantoll

  • Status changed from new to pending

Replying to benth:

You'll have to wait for a test case.

We need one to look into this. You can use this as a starting point: http://jsfiddle.net/tj_vantoll/fwk8R/.

comment:4 Changed 3 years ago by benth

  • Status changed from pending to new

comment:5 Changed 3 years ago by scottgonzalez

  • Status changed from new to pending

You forgot to click Update in order to generate your fiddle. That's just a copy of the original fiddle that tj.vantoll provided.

comment:6 Changed 3 years ago by benth

  • Status changed from pending to new

My apologies. Try this:

http://jsfiddle.net/JnGJN/3/

Last edited 3 years ago by benth (previous) (diff)

comment:7 Changed 3 years ago by scottgonzalez

  • Status changed from new to open
  • Summary changed from Draggable: relative_container fails to get unset when containment changes to Draggable: Changing containment option doesn't work

comment:8 Changed 3 years ago by Ben Higgins

  • Resolution set to fixed
  • Status changed from open to closed

Draggable: fix changing containment

If containment was set such that relative_container is set by _setContainment, and then containment changes to e.g. "document", "window", or an array, relative_container would not be unset, causing incorrect containment of the draggable.

Add a unittest to check that containment with an array works after previously being set to "parent".

Fixes #9733 Closes gh-1176

Changeset: 0bb807bb42af87bf4c6dd4d71808b12c08d316e7

comment:9 Changed 3 years ago by tj.vantoll

  • Milestone changed from none to 1.11.0
Note: See TracTickets for help on using tickets.