Issue #2458Opened December 17, 2019by angyLe0 reactions

[Question] Setting of default value for css property in StyleManager config does not affect style of new added block?

Question

I have a question. When css property is added to StyleManager configuration, for example I added color and set defaults to green (just for test):

name: 'Typography', open: false, buildProps: ['color'], properties:[{ name: 'Font color', property: 'color', defaults: "green"}, …

Looks like it does not affect text color of new added blocks? I dropped text block to canvas - text color is black. When I open style manager panel, i see that color is set to green. The same is with other properties I tried (width, height).

Answers (3)

artfDecember 18, 20190 reactions

Hi @angyLe the style manager just builds properties, in a kind of "blind-way", and some of their properties don't affect directly the target (component/rule). In this case the defaults it's more like a hint to show to the user when the property has no value. For this reason, from a practical point of view, you have to build your properties by following the CSS specifications and making them different doesn't make that much sense.

angyLeDecember 18, 20190 reactions

I didn't want to make properties different then in specification. I just wanted to set default value for existing properties. For example i want that width of the text box will be 100px, so when it is added to canvas it will be 100px . I thought than i can configure it in StyleManager by setting defaults for property ''width'. But it looks like it doesnot affect width of the box which was added to canvas. Or am i doing something wrong? How can i achive this?

balchenDecember 18, 20190 reactions

@artf I'm sorry, I couldn't understand your answer (@angyLe and I work together on implementing grapesjs in our system, so I know what the question was).

When I read your answer, it is my understanding that you are saying the following:

  1. default values for properties are not immediately applied to new instances of components
  2. default values for properties are shown in the Style Manager as if they have been applied to the component, even if they actually haven't

That doesn't sound right, so I'm thinking I'm not understanding your answer, or perhaps that you are answering based on a different understanding of the question.

I would be very interested in an elaboration on how we are supposed to use defaults and if this is the way grapesjs will behave if we use defaults.

The question's background is to do with dragmode: absolute. We want to use grapesjs to do fixed designs, so we use grapesjs with dragMode: absolute.

When we do that, we see that some existing components such as the Text component don't work well when dragged onto the canvas because it has width: auto and height: auto as its default. As you type into it, it will expand to the edges of the canvas, which isn't what you want when you're using dragMode: absolute, and the only way to force it back to a fixed size is to drag the right-bottom sizer back from the edge.

To avoid this, we tried setting default values for the width and height properties so that any component would be dragged to the canvas with correct settings.

How can we accomplish that in the best way?

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.