Issue #404Opened October 11, 2017by thecodefish9 reactions

Changing CSS properties on a component with an existing class modifies that class instead of adding a new one

Question

You can see this in action on the demo (http://grapesjs.com/demo.html). Select one of the nav items ('Web' for example) - note that it has an existing class of menu-item. If you now change some of the properties, such as text alignment, it applies those changes to the menu-item class, which affects the other instances ('Template', 'Builder').

Is it possible to force GrapesJS to apply a new 'unique' class and apply the changes there - similar to how it works if you make changes to a component with no existing classes (c1234 for example)?

Ultimately I want any Style changes to only apply to the selected item - never to other instances of the same type.

Thanks

Answers (3)

thecodefishOctober 11, 20175 reactions

I was thinking that the behaviour could be something like this:

Default (current setup):

  • If element has no classes, create unique class based on cid and apply styles
  • If element has classes, apply styles to the union of those classes (or whatever classes are selected in the UI)

Toggled behaviour

  • Test if element has an existing class based on the cid, if one does not exist, create one
  • Always apply custom styles to the cid class only
artfNovember 17, 20173 reactions

Hi @thecodefish what do you think about this approach? https://codepen.io/artf/pen/jaaKvq

You will see there how to make selectors private (not stylable by the user) and the usage of the new avoidInlineStyle option which allows you to style components (not class selectors) without losing the responsivity and the use of states (eg. :hover)

artfOctober 11, 20171 reactions

I'd say you have 2 options:

  1. Just deselect the class, in this case, the style manager scope will change to the component and not the rule
  2. Add a new class to the component, instead of .menu-item rule you will get .menu-item.your-new-class

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.