Condition for style in parent often needs to be duplicated in child

Not sure how this could be solved, but I often find myself in a situation where I have a condition in a Conditional Style on a parent element, that needs to be duplicated on a child. Here’s a typical example. I have a a container with a text child component. Let’s say this element has a active/inactive state and white background-color with dark text when inactive, and dark background with white text when active:

image

As color is not a valid style property on container components, I will need to duplicate the conditional style to the text component to set the inverted color in this case.

If possible, it would be desireable to only specify this condition once.

Hi,

There are possible ways to achieve this behavior without duplicating conditional styles:

  1. If “Text Color” doesn’t have any specified default colors, it will default to having a white color on a dark background, or a black color on a light background.
  2. It is also possible to have a conditional style on the property “Color” on the parent container. This will control the color of the Text component underneath, if the text inherits color from its parent, which is default behavior. “Color” can be found in conditional styles for a container, under the “Background” category.

Thanks
Rhys
Appfarm

Hi,

  1. This would work if the default white color is correct for one of the states.
  2. Color is not listed in conditional style on container components.

Cheers!

/Kenneth

Hi,

Could you share what it looks like for you for a conditional style on a Container? For me, Color is available as a conditional style, as seen in the image. This property controls the color for all child components who inherit their color from the parent. You can read more in our Docs

Rhys

Ah ofc, there it is - thanks!

1 Like