applying custom class to component doesn't seem to be working
Question
I'm adding a class on a component when certain conditions aren't met, in this case when there's no href set. I viewed the source and see the "nolink" class in the source but it's not setting the background color to red and I'm not seeing it when inspecting the element, this is how I'm trying to add it, but when I do cc.getAll() I'm not seeing the nolink class so I'm not sure where things are breaking down
var cc = editor.CssComposer;
var nolink = editor.SelectorManager.add('nolink');
var rule = editor.CssComposer.add([nolink]);
rule.set('style', { 'background-color': 'red' });
I also tried editor.CssComposer.setRule('.nolink', {'background-color':'red'}); but that didn't seem to work either
Answers (1)
I also tried editor.CssComposer.setRule('.nolink', {'background-color':'red'}); but that didn't seem to work either
setRule is the right API to use and it works, but it creates only the rule, you have also to add the class to the component if you want to see it in canvas (eg. editor.getSelected().addClass('nolink'))
Related Questions and Answers
Continue research with similar issue discussions.
Issue #2323
Possible to add background image or video?
Hi, Installed grapesjs locally and added the blocks-basic plugin and local storage. Everything seems to be working fine, except the backgro...
Issue #3309
BUG: TextNodes interfere when changing content on element
Version: 0.16.44 Hi @artf I have a custom block with a custom button component, which its content is similar to this one. <a data-gjs-type=...
Issue #2657
[Bug]: custom style property is not working when toRequire attribute is set
Are you using the latest release (older versions are NOT supported)? YesWhat is the expected behavior? Custom style property applying to co...
Issue #2928
BUG: Select the initial background color doesn't work
Version: 0.16.18 Bug: Select the initial background color is not working How to reproduce it: https://imgur.com/xqkt46E Actually:Component'...
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.