Editor.Css.setRule API not working as expected, it is not updating the rule existing rule.
Hi @FaisalShaikhHA this is expected behaviour but I guess the documentation of setRule is a bit misleading. The rule is actually updated (it doesn't create a new one with the same selector) but styles are simply replaced. This is what you should do if you need to add new styles instead of replacing them I guess I can...
Read full answer below βQuestion
GrapesJS version [X] I confirm to use the latest version of GrapesJS What browser are you using? Version 112.0.5615.137 (Official Build) (arm64) Reproducible demo link https://jsfiddle.net/yhj6qa1u/6/ Describe the bug How to reproduce the bug?Select a component and add some style using Style Manager.Use editor.Css.setRule to set some style for that particular component, notice the previous styles are removed but as per the documentation it should update the CSS rule. What is the expected behavior? It should update the existing rule. What is the current behavior? It removes the existing rule r...
Answers (3)
Hi @FaisalShaikhHA this is expected behaviour but I guess the documentation of setRule is a bit misleading. The rule is actually updated (it doesn't create a new one with the same selector) but styles are simply replaced. This is what you should do if you need to add new styles instead of replacing...
Thanks @artf for the clarification
The behavior you're observing with editor.Css.setRule is not a bug but rather how the GrapesJS CSS Composer API is designed to handle rule updates. When you call editor.Css.setRule(selector, styleObject), if a rule with that exact selector (and other context like media query, state, etc.) already e...
Related Questions and Answers
Continue research with similar issue discussions.
Issue #6458
Sector.setName doesn't work
GrapesJS version [x] I confirm to use the latest version of GrapesJS What browser are you using? Chrome Reproducible demo link https://jsfi...
Issue #5460
Loading `component` and `styles` from `pageManager`
GrapesJS version[X] I confirm to use the latest version of GrapesJSWhat browser are you using? Chrome v117.0.5938.149Reproducible demo link...
Issue #4356
Selector:remove event does not exist
GrapesJS version [X] I confirm to use the latest version of GrapesJS What browser are you using? Chrome 101 Reproducible demo link https://...
Issue #5982
Component styles such as md:flex-row(tailwind) are removed
GrapesJS version[x] I confirm to use the latest version of GrapesJSWhat browser are you using? Chrome 126.0.6478.127Reproducible demo link...
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 βBrowse Plugin Categories
Jump directly to plugin category pages on the marketplace.