Repository navigation
Block Supports: Add translate property on X and Y axis to Transform supports - #86282
aaronrobertshaw wants to merge 6 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. Props Bot commandsYou can trigger Props Bot actions by commenting on this PR:
Updated as activity occurs, without notifying anyone named here. Add the 📦 Bundle sizeSize Change: +1.17 kB (+0.01%) Total Size: 8.67 MB 📦 View Changed
⚡ PerformanceShow the resultsClient side metrics exclude the server response time. front-end-block-theme
front-end-classic-theme
media-processing
media-upload
post-editor
site-editor
🏁 Flaky testsSome tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information. Undo restores the post selection when another synced entity is loaded (RTC WebSocket) in
|
a49cb25 to
45793e8
Compare
d765b3a to
3256c31
Compare
4584d08 to
acaae5c
Compare
3256c31 to
a17eee9
Compare
acaae5c to
5132186
Compare
a17eee9 to
8a4cde4
Compare
5132186 to
f2fb802
Compare
8a4cde4 to
c805078
Compare
c805078 to
71daabc
Compare
There was a problem hiding this comment.
These PRs are really fun! One question re: the toolspanel menu — currently this splits the X and Y offsets out individually:
Whereas the setting for the block itself is just translate. Are we splitting them out here to make it easier to reset values individually?
While testing, it felt a tiny bit cumbersome having to click X offset and Y offset individually in order to reveal the controls. So I was wondering if it'd be worth combining them in the menu as one item (e.g. Offset or Translate) so that they're shown/hidden as a group? The side effect is that resetting would also be for the whole group, but on balance I think that might be okay?
(This is not a strongly held opinion, just observing that separate x + y menu items felt possibly a little too granular).
|
Related to the grouping X and Y axis, it looks like we need to decouple them further for viewport states. Currently, if I set some values for X and Y on desktop, and then set only a value for X on mobile, it saves the current desktop Y value under the mobile attribs too, so that if I later decide to change that value for desktop it'll persist on mobile. I think we should try to save only the explicitly set axis for viewport states. |
9ee9951 to
5a64303
Compare
71daabc to
1fe333c
Compare
1fe333c to
34f995f
Compare
b421623 to
acba541
Compare
0b6467e to
55ad7b9
Compare
|
No blockers, but a couple of considerations:
Edit: I just noticed @andrewserong's comment which includes a screenshot where the inputs are arranged in a row. Disregard my comment if this was already implemented :D |
e60c57a to
78b44f8
Compare
55ad7b9 to
f556e33
Compare
The translate feature saves an offset inline like the rotation. An offset replaces the Global Styles offset whole, and an axis it leaves out is 0, as in CSS. In the editor, the X and Y fields start from the inherited values, and changing one axis saves both. Group, Heading and Video adopt it. Transform tools, including the offset, are switched on by appearanceTools.
Setting only the X offset on mobile now saves the block's own Y offset with it, so mobile does not render Y as 0.
The offset tests now use Group for a block without a transform selector and Button for a block with one, so they do not depend on the Image block. The sanitize test uses Heading, as it already has a Group case.
f556e33 to
040fc31
Compare
|
I'm still able to repro the issue with X and Y axis from my comment above btw. What I'm doing (using a Group block):
The new Y value updates on desktop, but on mobile the old 35px value is preserved. This is the block attrib markup after the changes: (note that I never changed the value of Y on mobile, so I'd expect it to continue using whatever the current Desktop value is. I'd also expect there to be no explicit value for Y in the @mobile object unless I'd set it for that viewport) |
Each layer now sets only the axes it has, as --wp--style--translate-x and --wp--style--translate-y, and translate reads both with var(). The Offset panel saves only the axis that changed and shows the other as a placeholder. The two properties are registered with @Property so nested blocks do not inherit an offset. kses keeps the new declarations.
|
Thanks for testing again @tellthemachines 🙇 The cause was that Each axis now has its own custom property. The output is That covers block instances, states and Global Styles. Your steps should now save only
|
An inherited X of 3rem showed as 3 with px, because the empty field gave UnitControl no unit. Pass the selected unit on its own so the select matches the placeholder and a typed value saves in that unit.


Important
This builds on #86240 and should merge after it.
Core backport: WordPress/wordpress-develop#15465
Related:
What?
Adds an X and Y offset to the Transform block support, via
translate. Group, Heading and Video opt in.Why?
Blocks cannot be nudged from where the layout puts them. The grid canvas in #85505 needs it too.
How?
style.transform.translateis{ x, y }, each one length or percentage.--wp--style--translate-xor--wp--style--translate-yfor each axis set, plustranslate: var(--wp--style--translate-x, 0) var(--wp--style--translate-y, 0).@propertywithinherits: false, so nested blocks keep their own offset.calc(), lists and azkey. KSES keepsvar()intranslate, as Core does elsewhere.Testing Instructions
Use Twenty Twenty-Five.
21px 45px.@mobilesaves onlyx.theme.jsonstyles above. On a Heading, X shows3remas a placeholder. Set Y to1rem. Onlyyis saved. Both apply.Screenshots or screencast
86282-offset.mp4
Use of AI Tools
Written with Claude Code, then reviewed and tested.