Issue #2836Opened June 16, 2020by RJCAM1 reactions

[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)

artfJune 18, 20201 reactions

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.

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...

Browse Plugin Categories

Jump directly to plugin category pages on the marketplace.