Problem replacing component in absolute dragMode
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)
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.
Issue #3211
How to move components
Hello dear: I want move a component to first/end in the wrapper programmatically, i think something like editor.getWrapper().add(editor.sel...
Issue #3185
How to get the models trait of a component?
Hi there, I added a new type "array" to the TraitManager. So I can add several sub traits. On one point I have to check the traits of the m...
Issue #2374
Component style is not updated after the drag event in Dragmode('absolute')
In the new dragmode the component's style is not updated after dragging the component. Expected behaviour:Drag element by clicking on the c...
Issue #3059
Header goes on a textbox
Hello, so first thanks to have create GrapesJs this very usefull. I have an issue i add an header on my page and that's the code i add for...
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
GJS.Market Is Now Available for India ๐ฎ๐ณ
GJS.Market is expanding its global presence with a dedicated experience for developers, agencies, SaaS companies, and digital creators in India
Tutorial
How to Build an AI-Powered Page Builder with GrapesJS in 2026
What we learned building GJSDocs โ from simple AI text generation to structured, context-aware visual editing
Tutorial
How Much Does It Cost to Build a SaaS Page Builder in 2026?
How much does it cost to build a SaaS page builder in 2026? Explore realistic development costs, timelines, features, and how using GrapesJS can reduce
Browse Plugin Categories
Jump directly to plugin category pages on the marketplace.