Skip to content

[BUG] Dragging within an SVG with fixed viewBox dimensions #1414

@andreaskienle

Description

@andreaskienle

When the width and height dimensions of an svg are different from the viewBox dimensions, dragging items doesn’t work correctly: The mouse pointer location does not correspond to the dragged item’s location.

<svg viewBox="0 0 100 100" width="500" height="500">
  <motion.rect width="10" height="10" drag />
</svg>

error

Expected behaviour
When the viewBox corresponds to the width and height, there is no such issue.

<svg viewBox="0 0 500 500" width="500" height="500">
  <motion.rect width="50" height="50" drag />
</svg>

expected

Is there any way of getting a correct drag behaviour in an svg with a fixed viewBox? It would be very inconvenient to change the viewBox (and recalculating the entire content) every time the SVG’s dimensions change (e.g. after resizing the window).

Sandbox
https://codesandbox.io/s/musing-bush-dc4vh?file=/src/App.js:475-596

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions