Opened 4 years ago

Closed 4 years ago

Last modified 4 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 4 years ago by Scott González

Owner: set to benth
Status: newpending

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

comment:2 Changed 4 years ago by benth

Status: pendingnew

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 4 years ago by tj.vantoll

Status: newpending

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 4 years ago by benth

Status: pendingnew

comment:5 Changed 4 years ago by Scott González

Status: newpending

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 4 years ago by benth

Status: pendingnew

My apologies. Try this:

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

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

comment:7 Changed 4 years ago by Scott González

Status: newopen
Summary: Draggable: relative_container fails to get unset when containment changesDraggable: Changing containment option doesn't work

comment:8 Changed 4 years ago by Ben Higgins

Resolution: fixed
Status: openclosed

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 4 years ago by tj.vantoll

Milestone: none1.11.0
Note: See TracTickets for help on using tickets.