How to remove class selector css rule
It makes sense, now I just have to find a way to add this feature to my builder. Thank you @Ju99ernaut!
Read full answer below ↓Question
I'm using componentFirst set to true to let my users apply needed style to component they selected.
Selecting a component which is applied a css class specific to the component type, and clicking "Sync" button causes the selector change from the component ID to the relevant css class.
Now I can't find a way to go back and throw away the css rule that has the component class as the selector, hence every new instance of that component has the same style.
Thanks for your help!
Answers (4)
It makes sense, now I just have to find a way to add this feature to my builder. Thank you @Ju99ernaut!
Hello,
For future questions or technical issues, which aren't bugs, GitHub's Discussions tab is the place to be.
Don't forget to close this issue if it is resolved or write a new detailed message in Discussions -> Q&A category (and close this issue).
Thank you for your understanding.
Hi @ltenti-eventboost I'm not sure If I understand exactly where is your issue.
When you're editing with componentFirst enabled, the editor applies style changes on a component-specific CSS rule (eg. #cmp-id { color: red }).
When you hit the "Sync" button, all the styles are moved to the current class selector and those inside the component-specific rule are removed .selected-class { color: red } #cmp-id {}.
So, from what you've described seems legit to me but maybe I'm missing something.
Thanks for reporting this, @ltenti-eventboost.
Great question about [QUESTION] How to remove class selector css rule. The recommended approach with StyleManager is to use the event-driven API.
Start here:
- Check the GrapesJS documentation for your specific module
- Look for the
on()event listener method - Most operations can be achieved by listening to editor and component events
Common patterns:
// Listen for changes
editor.on('change', () => console.log('something changed'));
// Component lifecycle
editor.on('component:mount', (c) => console.log('component ready', c));
editor.on('component:update', (c) => console.log('component updated', c));
If you're still stuck:
- Share a minimal CodeSandbox reproduction
- Include what you've already tried
- Mention your GrapesJS version
- The community is here to help!
Related Questions and Answers
Continue research with similar issue discussions.
Issue #4310
Style Manager is inaccurate when using combined CSS selectors which contains "bout" and componentFirst = true
GrapesJS version [X] I confirm to use the latest version of GrapesJS What browser are you using? Chrome 100 Reproducible demo link https://...
Issue #3200
Help needed: Get the component that a block being dropped onto?
Hello, If I drag and drop a block on a dynamically added component, how can I get/access the component that the block is dropped onto? I se...
Issue #3627
[QUESTION]: I'm trying to duplicate the page, but the styles are not geting applied due to the Ids, changes to -2,-3 at the end.
This is what my function looks like. I am trying duplicate the page, the HTML part is fine but as css is applied through ids, when a new pa...
Issue #4576
Clicking 'wrap for style' button affects the inner components of other components inside the same text box
GrapesJS version[X] I confirm to use the latest version of GrapesJSWhat browser are you using? Chrome 104.0.5112.101 Reproducible 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.