Issue #2464💬 AnsweredOpened December 21, 2019by alemenciones0 reactions

Problem replacing component in absolute dragMode

快速解答by artf

The code, more or less, seems ok, be sure to check styles contains the position properties (and the component has also the absolute position). If it's not working yet try to create a reproducible demo, please

Read full answer below ↓

Question

I have a problem to replace a componente in the same position (top/left), the new component is always added in the positions top: 0px / left: 0px;

I'm triyng something like this:

const selectedComponent = editor.getSelected();
const coll = selectedComponent.collection;
const at = coll.indexOf(selectedComponent);

var styles = selectedComponent.getStyle() || {};   

coll.remove(selectedComponent);

let newComponent = coll.add(component, {
   fromAddNewComponent: true,
   at: at,
});

newComponent .setStyle(styles);

But setStyle() is not working this time...

Answers (1)

artfDecember 25, 2019

The code, more or less, seems ok, be sure to check styles contains the position properties (and the component has also the absolute position). If it's not working yet try to create a reproducible demo, please

Related Questions and Answers

Continue research with similar issue discussions.

Paid Plugins That Match This Issue

Curated by issue keywords and label relevance to help you ship faster.

View all plugins

Loading paid plugin recommendations...

Free option

Check the open-source GrapesJS plugins on GitHub or run a quick search in our free catalog.

Browse free plugins →
Premium option

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.

All tutorials →

Browse Plugin Categories

Jump directly to plugin category pages on the marketplace.