Skip to content
This repository has been archived by the owner on Nov 9, 2021. It is now read-only.

Bounds in container doesn't seem to apply #168

Open
bubbleheadinc opened this issue Aug 7, 2020 · 4 comments
Open

Bounds in container doesn't seem to apply #168

bubbleheadinc opened this issue Aug 7, 2020 · 4 comments

Comments

@bubbleheadinc
Copy link

Hi, I'm starting to play with Vue Moveable and I'm trying to get the moveable to stay inside its container. I've set, draggable, dragArea, and snappable to the demo sandbox according to the docs. I have added a :container="$refs.container" to specify the container and set styles on the container and then try to set bounds.

The object can still be moved outside the container and the bounds seem to only apply to the document body and not the container. Shouldn't the bounds apply to the reference container or am I misunderstanding how this should work?

Here is a CodeSandbox with the issue. If the container is set, shouldn't the bounds apply to the container so that the moveable should be kept within the green box container?

Thank you for any help!

@liveclickermike
Copy link

I'm also having this issue.. I have a hacky workaround of measuring the top/left of the container and manually setting bounds equal to the container bounding box, but this doesn't work if the page changes in layout above the container (and throws the position of the container off from initial page load)

Any help would be greatly appreciated!

@josvos
Copy link

josvos commented Oct 23, 2020

AFAICS, the container prop expects a HTMLElement, not a Vue component that $refs.xxx is. BUT: I do not manage to pass such an element (as a quick test I did this with document.querySelector), because then I get [Vue warn]: Error in nextTick: "RangeError: Maximum call stack size exceeded". According to https://www.gitmemory.com/issue/probil/vue-moveable/27/543120459 this is due to the way vue-moveable handles its props.

Any suggestions on how to pass something useful to the container prop, as I really need to restrict the frame to one part of my page.

@JohannesSchwegler
Copy link

@josvos
Copy link

josvos commented Feb 19, 2021

FWIW: I use a local copy now, in which I added a prop containerSelector (string) and in mounted() I do containerElement = document.querySelector(this.containerSelector). That containerElement is then used as first parameter for the Moveable() constructor.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants