Environment
Bricks 2.5-beta2, WordPress 7.1.5, PHP 8.4.28
Bug 1: switching a toggle off stores an empty value
Steps
- Create a component containing a Button element.
- Add a toggle property connected to the Button’s “Outline” (or “Circle”), with no default.
- On a component instance, switch the property ON.
- Switch it OFF again.
- 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.phpline 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.phptestsisset( $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' : nullalso counts as ON.
Bug 2: a false default looks OFF in the builder but is ON on the front end
Steps
- Create a component whose toggle property (connected to a Button’s “Outline”) has
"default": false. We did this with thebricks/create-componentability, which
accepts that value. - 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).