Repository navigation
Enhancement: Add linkedByDefault spacing setting to theme.json - #84719
sarthaknagoshe2002 wants to merge 3 commits into
Conversation
🤖 PR meta 🤖🎉 PropsIf you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. Updated as activity occurs, without notifying anyone named here. Add the 🏷️ LabelsThis pull request needs exactly one label indicating its type, and has 0.
Read more about Type labels in Gutenberg. If you cannot add labels yourself, a reviewer can do it for you. |
There was a problem hiding this comment.
The new effects make a default prop reset the user’s linked state whenever linkedByDefault changes after mount. This is not how we expect "default" props to work. Can we apply linkedByDefault only in the state initializer and remove usePrevious, inputValuesRef, and both effects?
| const inputValues = values || DEFAULT_VALUES; | ||
| const inputValuesRef = useRef( inputValues ); |
There was a problem hiding this comment.
Can we use the same initialization-only approach here and remove the synchronization effect, previous-value tracking, and refs? Comparing sides by reference resets the user’s selected view when a parent passes a new array with identical contents, even without the new setting. Applying the default only in getInitialView would avoid that regression and leave subsequent link changes under the user’s control.
What?
Closes #70646
This PR introduces a new
theme.jsonsetting,settings.spacing.linkedByDefault, which allows theme developers to determine whether margin and padding controls should have their sides linked or unlinked by default in the block editor.To ensure strict backward compatibility, this setting defaults to
true. It accepts either a global boolean or a granular object ({ margin: boolean, padding: boolean }) for independent control.Why?
Currently, when a user adds a block and attempts to adjust the margin, the top and bottom margin settings are linked by default, which often results in both margins being changed simultaneously. This contrasts with standard block spacing paradigms where typically only a top margin is applied.
While developers could previously use the
register_block_type_argsfilter to restrict spacing support to only thetopside, this aggressively removed the ability for users to edit the other sides. This PR provides a non-destructive UI solution that makes it easier to adjust a single side by default without taking any design tools away from the editor.How?
linkedByDefault(boolean or object) to theme.json schema and allowlisted it in the PHP and JS style engines.DimensionsPanelto fetch the setting and pass strictmarginLinkedandpaddingLinkedbooleans.BoxControlandSpacingSizesControlto default to unlinked when empty, while preserving the linked view for existing uniform attributes.Testing Instructions
theme.jsonto include the new setting. Test both the global boolean and the object override:linkedByDefault: falsepreference to match the block's existing data.Screenshots or screencast