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
Messaging on gjs.market: talk to a studio before you buy, not after
We've launched private messaging between buyers and studios. One thread per buyerβstudio pair, the whole history in one place.
Tutorial
Vanilla GrapesJS vs GrapesJS With Plugins: What You Actually Get Out of the Box (2026)
New to GrapesJS? See exactly what the stock editor gives you, where it falls short, and which plugins close the gaps β a beginner-friendly 2026 comparison
Tutorial
Lighthouse for GrapesJS: Audit Accessibility and SEO Without Leaving the Editor
Live WCAG 2.1/2.2 accessibility auditor + SEO manager for GrapesJS. Every finding is bound to the exact component β click to select, then one-click fix.
Browse Plugin Categories
Jump directly to plugin category pages on the marketplace.