Drag and drop broken in 20.2
Confirmed it's still working in v0.20.1, so it looks like the regression was introduced in v0.20.2
Read full answer below βQuestion
GrapesJS version
- I confirm to use the latest version of GrapesJS
What browser are you using?
Chrome v108
Reproducible demo link
see below
Describe the bug
How to reproduce the bug?
- Create a custom component
export const appearBlock = {
view:{
defaults:{
tagName: 'div',
attributes: {
class: 'appear-element_view'
},
styles:`
border: 2px dashed gray
`
}
},
model: {
defaults: {
type:'appear-element',
tagName: 'div',
attributes: {
class:'appear-element'
},
styles: `
.appear-element{
display:flex;
height:50px;
width:50px;
background-color:red
}
`
}
}
}
- Add it to the editor as a component and draggable block
editor.Components.addType('appear-block', appearBlock)
editor.BlockManager.add('id-appear', {
content:{ type: 'appear-block'},
label: "Custom Appear block"
})
- Set the editor to absolute drag mode when the component added, then make the component itself absolute once it's dropped. reset the editor
editor.on('block:drag:start', (block) => {
if(block){
editor.setDragMode('absolute');
}
})
editor.on(`block:drag:stop`, (component, block) => {
if (component) {
editor.setDragMode("translate")
var res = component.setDragMode('absolute');
}
What is the expected behavior? The component stays where it is dropped (this works as expected in v 0.20.1)
What is the current behavior? The component snaps to the right side of the screen (this behaviour is new in 0.20.2)
Code of Conduct
- I agree to follow this project's Code of Conduct
Answers (4)
Confirmed it's still working in v0.20.1, so it looks like the regression was introduced in v0.20.2
The component is no longer draggable once it's added to the canvas either.
I'll prepare a fix for the next release.
Thanks for reporting this, @wunksert.
Great question about Drag and drop broken in 20.2. The recommended approach with StyleManager is to use the event-driven API.
Start here:
- Check the GrapesJS documentation for your specific module
- Look for the
on()event listener method - Most operations can be achieved by listening to editor and component events
Common patterns:
// Listen for changes
editor.on('change', () => console.log('something changed'));
// Component lifecycle
editor.on('component:mount', (c) => console.log('component ready', c));
editor.on('component:update', (c) => console.log('component updated', c));
If you're still stuck:
- Share a minimal CodeSandbox reproduction
- Include what you've already tried
- Mention your GrapesJS version
- The community is here to help!
Related Questions and Answers
Continue research with similar issue discussions.
Issue #5720
Propagating component defaults can break layers when child comments are introduced
GrapesJS version [X] I confirm to use the latest version of GrapesJS What browser are you using? Chrome v122 Reproducible demo link https:/...
Issue #6152
CSS added via custom code persists after custom code component is removed
GrapesJS version [X] I confirm to use the latest version of GrapesJS What browser are you using? any Reproducible demo link https://grapesj...
Issue #5263
Deleting a component without deleting its corresponding style, will adding new components later cause style conflicts?
GrapesJS version [X] I confirm to use the latest version of GrapesJS What browser are you using? latest version of Chrome Reproducible demo...
Issue #4191
We are trying to store the data from grapesJS editor in Angular 10 application, getting CORS error, image attached below
GrapesJS version [x] I confirm to use the latest version of GrapesJS What browser are you using? Chrome 99.0.4844.5 Reproducible demo link...
Paid Plugins That Match This Issue
Curated by issue keywords and label relevance to help you ship faster.
Loading paid plugin recommendations...
Check the open-source GrapesJS plugins on GitHub or run a quick search in our free catalog.
Browse free plugins βPremium plugins ship with support, regular updates, and production-ready features β save days of integration work.
Browse premium plugins βRelated tutorials
In-depth guides on the same topic.
Tutorial
How to Build a Production GrapesJS Editor: The Complete Walkthrough of Brief, Preset, Plugins, and Services
A complete walkthrough of building a production GrapesJS editor: how to choose a preset, pick plugins, and scope setup services without burning a sprint.
Tutorial
Embed GrapesJS in Your SaaS: A Weekend Guide
Embed GrapesJS in your SaaS and ship a white-label page builder over a weekend. Honest tradeoffs, real code, and the plugins that close the UX gap.
Tutorial
Big Updates: TinyMCE 8 and Placeholder 2.0 for GrapesJS
In May we shipped major updates to two of our most popular GrapesJS plugins β TinyMCE Inline Text Editor and Placeholder.
Browse Plugin Categories
Jump directly to plugin category pages on the marketplace.