Repository navigation
Block Supports: Add translate property on X and Y axis to Transform supports - #86282
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.18 kB (+0.01%) Total Size: 8.7 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. Should insert content using the global inserter in does not select blocks in the canvas preview when editing from the sidebar (Site Editor v2) 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
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
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) |
|
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
|
736a78c to
8e80e95
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.
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.
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.
031c70c to
6e5b128
Compare
|
Thanks for iterating on this!
Is there any way we can show the inherited value as an editable value, but only save it if it's actually changed? Otherwise an edit to the field will cause a jump (this is most obvious if you're editing with arrow keys i guess) |
An empty offset field shows the inherited value as a placeholder, but ArrowUp and ArrowDown stepped from 0, so an inherited 35px became 1px. They now step from the placeholder in its unit. Untouched axes still save nothing. Global Styles states now fall back to the Default state for each axis, so a Mobile field shows and steps from the Desktop value too.
|
Thanks for the nudge, especially on the keyboard adjustments. An empty axis still shows the inherited value as a placeholder. The arrow keys now step from it though so on Mobile an inherited Also, only the axis you change gets saved. Global Styles was missing the Desktop value on Mobile altogether, so that now works the same way. |
andrewserong
left a comment
There was a problem hiding this comment.
This is testing very nicely for me! And the placeholder state feels really good when overriding translate/offset at viewport sizes:
This is a tentative approval, because it's quite a big piece of work, but I think it'll likely be easier to land the big PR (this one) first, and continue tweaking things in follow-ups, rather than getting too bogged down in details. Behaviour-wise, it's all working nicely for me in testing at global styles, individual block level, and in responsive overrides in the editor and site frontend 👍
Things that might be worth tweaking in follow-ups:
- The UI feels a bit chunky to me with everything showing:
- One option: switch back to the two UnitControls sitting side-by-side and leave the
UnitRangeControlchanges to a follow-up. - Another option: Remove the
Offsetheading, and individually label theseX offsetandY offsetin the panel
- The min/max on the range slider feels quite broad to me so I found the range control hard to use for tweaking the offset just a little bit here and there (in
pxit's a range of 2000px). This is in contrast to rotate, where it feels quite natural to me. This might be another argument for going for UnitControls for now.
- Should we allow presets for these values eventually? In some ways they're a bit like height and width, though arguably this is more of a "tweak" / one-off design kind of tool
Anyway, that's more words than I intended to add to this comment. But overall here, my vote would be to land this sooner and iterate in follow-ups. What do you think?
Code-wise this touches lots of different areas, but all up it seems pretty consistent with existing conventions. The only thing I thought could be split off into another PR if need be was just the UnitRangeControl placeholder / controlLabel change.
| @property --wp--style--translate-x { | ||
| syntax: "<length-percentage>"; | ||
| inherits: false; | ||
| initial-value: 0; | ||
| } |
There was a problem hiding this comment.
Oh, clever! Nice way to handle the CSS var inheritance issue 👍
There was a problem hiding this comment.
Honestly, its the first time I've gotten to use it. Nice bonus when I suggested the approach to Claude and it seconded it.
|
Appreciate the in-depth review @andrewserong 🙇 +1 on landing this and iterating from there. Your suggestions are pretty much matching what I already had on my list. I'll get this merged and publish the tweaks to polish things further. For now, I'll leave the |


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.