[Bug]: Styles allways applied to classes
Question
Hello,
I have a Problem with styling individual Items.
The following html Code:
<div class="ddm-flex-cols">
<div class="ddm-flex-cols-element">
This is some Text
</div>
<div id="icbp" class="ddm-flex-cols-element">
Text
</div>
</div>
<style>
.ddm-flex-cols {
display: flex;
flex-direction: row;
margin: -16px;
padding: 16px 0px;
flex-wrap: wrap;
}
.ddm-flex-cols-element {
flex-grow: 2;
margin: 16px;
flex-shrink: 0;
flex-basis: 0;
}
#icbp {
max-width:300px;
}
</style>
Loads fine. But when I Click the Component with "#icbp" then the class .ddm-flex-cols-element will get the style max-width. Setting this.el.style while rendering the Object is also Integrated to the CSS (Id only) the Docs tell changes to this.el will not being saved to Components.
Reproduction with DEMO is not possible for me because its only happening with some loaded canvas styles. I'm using version 0.14.57 My Config for reproduction:
let options = {
container: '#gjs-content-editor',
protectedCss: '',
style: '',
canvas: { styles: ['/some/file.css'] },
};
Answers (3)
Can you please try to add this to your options avoidInlineStyle: true and let me know
Hi @artf , Yes I tried this, still no luck. I had the time to minimize this issue to a codesandbox:
https://codesandbox.io/embed/jnplq7op55
Position of the protectedCss Content can be varied put it to style or in a file and load it by cvanvas.style the behavior keeps the same.
The Issue is gone by deactivationg selectors before adding components:
editor.on('selector:add', selector => selector.set({
active: false, // disable the selector
// or
private: true, // hide the selector
}));
from #1979 (both versions work) for me this is a solutuion but I think in some cases it might not.
Best regards
Ok, the problem happens here: https://github.com/artf/grapesjs/blob/e97afb429b4cada591e119025fcf34490cb0de8c/src/style_manager/index.js#L284-L285
if there is no CSS rule with the selector found on the component (in our case ddm-flex-cols-element) the rule is created and all its styles are moved to the rule. I think I made it for the optimization reason but now I'm not quite sure if it's the right approach...
Related Questions and Answers
Continue research with similar issue discussions.
Issue #1865
[Bug]: Grapes change page position
Hello, I found the following problem using grapes inside an html page: when you click on some elements of the editor, such as the arrow to...
Issue #1699
[BUG] Link elements are not copyable/deletable
In the editor, if we have link element with some classes, the editor does not allow to copy/delete the element. GrapesJS version: v0.14.50S...
Issue #509
Span are not editable as text
Hello Artf, I have a problem when importing some html templates. I was initially not able to see span texts. But after helping the editor r...
Issue #399
[Question] Can i push toolbar in current modal and current modal child?
Hello again @artf , i confuse about push toolbar in the element with specific class (ex: modal-trigger) the element code is : and in the /s...
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.