Skip to main content
Solved

How to drag svg from figma plugin and drop to figma canvas?


Prerana_Das

Drag svg from Figma plugin and drop to Figma file.

Like they did https://www.figma.com/community/plugin/884531262241804656/Drag-%26-Drop

I’m wanna develop this type of feature in my plugin.

Best answer by tank666

Since you are using Typescript, you need to respect its syntax and also return false:

figma.on('drop', (event: DropEvent) => {
    // Your code
    return false
})

Also add a condition for line 9 (on which you supposedly have an error) as in the example I gave you a link to:

github.com
View original

12 replies

Avokadomos
  • Active Member
  • 377 replies
  • September 22, 2022

Is this a question? 🤔


Prerana_Das
  • Author
  • 9 replies
  • September 22, 2022

sorry yeah


Avokadomos
  • Active Member
  • 377 replies
  • September 22, 2022

Can you explain further? This depends heavily on the plugin that you’re using.


Prerana_Das
  • Author
  • 9 replies
  • September 22, 2022

Please look back at my question again. And actually, Figma not allowing to create SVG Instance directly.

I got this error “‘postMessage’ on ‘Window’: SVGSVGElement object could not be cloned.”
in my plugin.


tank666
  • 4862 replies
  • September 22, 2022

Use the “Drop” event in code.js.
Check out the following official examples:


Prerana_Das
  • Author
  • 9 replies
  • September 22, 2022

I’m not sure why but when I try to use figma.on(‘drop’,…) it’s throwing errors


tank666
  • 4862 replies
  • September 22, 2022

I don’t see any errors here. But you probably need to update plugin typings.

GitHub

Prerana_Das
  • Author
  • 9 replies
  • September 22, 2022

I had update plugin typings but still


tank666
  • 4862 replies
  • Answer
  • September 22, 2022

Since you are using Typescript, you need to respect its syntax and also return false:

figma.on('drop', (event: DropEvent) => {
    // Your code
    return false
})

Also add a condition for line 9 (on which you supposedly have an error) as in the example I gave you a link to:

github.com

Prerana_Das
  • Author
  • 9 replies
  • September 25, 2022

Thank you so much for your help. It’s working now. But one typescript error still showing

if (node.appendChild) {
   node.appendChild(newNode);
}

Showing this “Property ‘appendChild’ does not exist on type 'DocumentNode | PageNode | SliceNode | FrameNode… etc”


tank666
  • 4862 replies
  • September 25, 2022

This condition is just written in order to bypass the error you indicated.


Prerana_Das
  • Author
  • 9 replies
  • September 25, 2022

Okay thank you


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings