NO BUG: CSS of invalid controls are still generated on the frontend

Browser: Any
OS: Any

First time I meet this logic. So, if it’s not a bug, can someone please explain to me.
For me, it’s really buggy because CSS rules of invalid controls override CSS rules of valid controls.

For example, I have three controls like this:

$this->controls['control_1'] = [
    'label' => esc_html__('Select A Value', 'textdomain'),
    'options' => [
        'a' => esc_html__('A', 'textdomain'),
        'b' => esc_html__('B', 'textdomain'),
    ],
    'default' => 'a',
    'type' => 'select',
    'inline' => true
];

$this->controls['control_2'] = [
    'label' => esc_html__('Size', 'textdomain') . ' (px)',
    'type' => 'number',
    'unit' => 'px',
    'placeholder' => '8px',
    'css' => [
        [
            'property' => 'width',
            'selector' => 'button'
        ],
    ],
    'required' => ['control_1', '=', 'a']
];

$this->controls['control_3'] = [
    'label' => esc_html__('Size', 'textdomain') . ' (px)',
    'type' => 'number',
    'unit' => 'px',
    'placeholder' => '8px',
    'css' => [
        [
            'property' => 'border-right-width',
            'selector' => 'button'
        ],
        [
            'property' => 'border-left-width',
            'selector' => 'button'
        ]
    ],
    'required' => ['control_1', '=', 'b']
];

Now, if we set the value of the “control_1” to “a”, save the builder. Then, change the value of the “control_1” to “b” and save the builder, the generated CSS contains both the rules of the “control_2” and the “control_3”. The logic of the required condition is OR but the result is AND?

I mean, if “control_1” is “b”, just set the “border-right-width” and “border-left-width” of the “button” element, do not set the “width”. But it doesn’t work like that.

Hi @wpclevel,

This is the description of the ‘required’ property for control arguments:

"Show control in relation to the setting of another control.

Parameter #1: control ID
Parameter #2: comparison operator: =, !=, >=, <=
Parameter #3: setting value

Example: 'required' => ['layout', '=', ['list', 'grid']],
Required condition: Show this control if setting value of control layout equals = either list or grid."


You can check it out here Element Controls – Bricks Academy.

I understand how it could be confusing due to the naming, but the ‘required’ property controls whether the builder shows or hides the control, not whether or not it’s evaluated.

So, it’s just to show/hide the UI of a control. I got it.

But, even though, CSS rules of a hidden control shouldn’t be generated. It’s redundant CSS which will cause the bug in the example I mentioned.