Re-render Component on Canvas when tagName has changed
@z1lk I already added such a thing for the next release
Read full answer below ↓Question
I'm trying to build a basic Header component that lets you select H1 to H6 with a trait. But when an option is selected, the canvas doesn't update. The change is visible in the code view, and if I move the element in the canvas with the drag tool, the tag then changes. I have been reading the API docs as well as the source, but I can't make the component automatically re-render. I suspect that Grapes is not listening for a change of the component tag name. What is the appropriate way to force a re-render in this case?
Answers (3)
@z1lk I already added such a thing for the next release
I'm not sure why el would be a string, but see the commit that closed the issue: https://github.com/artf/grapesjs/commit/e450cb98855d16ad819f1214350825a50e45e910 If you're using the latest Grapes version, the Component listens for a change of tagName and does the node replacement itself. So you sho...
Yeah this is because you can't change the tag name of an existing DOM element. Probably the solution would be, on tagName change, remove and replace the node (at the same position)
Related Questions and Answers
Continue research with similar issue discussions.
Issue #1511
[QUESTION] Change the html content of the selected component
I am trying to replace the html of the basic Text componet using the below code const component = editor.getSelected(); component.set('cont...
Issue #686
Trait view doesn't update input element when target value changes
If the target value (i.e. Component attribute/prop) is set manually and not via the trait input element, the input doesn't reflect that cha...
Issue #796
Can't drag component into canvas after styled element is cloned
Go to any of the demo, select a text box, give it a background color. Clone it. Then try to drag in another text component and it doesn't l...
Issue #1198
QUESTIONS : Find element in Model
I have custom component and it render below html, I want to update value of h4 tilte and other element on trait changed, but not sure how c...
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.
Browse Plugin Categories
Jump directly to plugin category pages on the marketplace.