WIP: Component toggle property stays ON after being switched OFF (2.5-beta2)

Environment
Bricks 2.5-beta2, WordPress 7.1.5, PHP 8.4.28

Bug 1: switching a toggle off stores an empty value

Steps

  1. Create a component containing a Button element.
  2. Add a toggle property connected to the Button’s “Outline” (or “Circle”), with no default.
  3. On a component instance, switch the property ON.
  4. Switch it OFF again.
  5. Save and view the front end.

Expected: The button is not outlined (or round), in the builder and on the front end.

Actual: The switch shows OFF, but the button stays outlined (or round) in the
canvas and on the front end. The instance’s properties holds an empty value
instead of 'off': {} in the builder state, an empty array once saved:

"properties": { "buttoncircle": [], "buttonoutline": [] }

Depends on the property’s default

Property default Value stored on switching OFF Result
none empty value stays ON
false empty value stays ON
true “off” correct

Why it shows as ON

  • Only the string 'off' clears the connected setting:
    includes/helpers.php line 2688, and the same check in the builder’s JavaScript
    ("toggle" === type && "off" === value, then delete the setting).
  • PHP: the empty array is copied into the element settings, and
    includes/elements/button.php tests isset( $settings['outline'] ) (line 143) and
    isset( $settings['circle'] ) (line 160), so it counts as ON.
  • Builder: an empty object is truthy in JavaScript, so
    settings.outline ? 'outline' : null also counts as ON.

Bug 2: a false default looks OFF in the builder but is ON on the front end

Steps

  1. Create a component whose toggle property (connected to a Button’s “Outline”) has
    "default": false. We did this with the bricks/create-component ability, which
    accepts that value.
  2. Add an instance and leave the switch untouched.

Expected: Not outlined in either place.

Actual: Not outlined in the builder (false is falsy in JavaScript), but outlined
on the front end (false !== 'off', so it is copied to the settings and isset() is true).

Hi @alanblair,

thank you for the report. I was able to replicate the issues and I’ve added it to our internal bug tracker.

Thanks,
Matej