[BUG]: Unable to add class when adding Dom Component
Question
GrapesJS Version used: 0.16.12 (current)
Just a strange behavior, I can add all the attributes I want when adding component directly inside canvas using dom components add function (like code below) but the editor always remove the class.
let component = editor.DomComponents.addComponent({
tagName: 'div',
content: 'Content text', // Text inside component
style: {
width: "100%",
height: "100px",
"background-color": "#ddd",
color: 'red'
},
attributes: {
title: 'divTitle', // This works
id: "divID", // This works
class: "someClass" // This is going to be removed
}
});
The class is only added if we create the component first and then assign a class to it. Example, we add the code above and then we add the code below:
component.addAttributes({
class: 'anotherClass'
});
Answers (1)
Yeah, you have to use classes property, but I agree that is confusing (that because classes are treated a bit differently), so I'll try to make the initialization possible also with attributes.class value
Related Questions and Answers
Continue research with similar issue discussions.
Issue #3674
BUG: Invisible webcomponents
Version: 0.17.19 What is the current behavior? That the added webcomponent is visible: When adding web components inside grapesjs container...
Issue #510
Add new class programatically
Hello Artf, I want to edit the styles of components (mostly imported html) without modifying all components with the same class. I tried to...
Issue #344
Add component to specific point on the cavnas
I'm adding a new component to the canvas using editor.addComponents({ ... }); but it's always added as the last element, to the bottom of t...
Issue #814
[QUESTION] Disable selectable, hoverable and editable options when Mobile view is on.
Hi, I want to disable to select, hover or edit the components of the editor when the Mobile view is on. I have tried using below code. But...
Paid Plugins That Match This Issue
Curated by issue keywords and label relevance to help you ship faster.
Loading paid plugin recommendations...
Browse Plugin Categories
Jump directly to plugin category pages on the marketplace.