Add support for layout responsive styles#78543
Conversation
|
Size Change: +1.18 kB (+0.01%) Total Size: 8.13 MB 📦 View Changed
ℹ️ View Unchanged
|
|
Flaky tests detected in d3ba307. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/26426745884
|
36c55e2 to
ef7d14c
Compare
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If 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. |
talldan
left a comment
There was a problem hiding this comment.
It's a lot of code, so I'm not sure I'm able to take it all in, but it looks pretty reasonable in terms of changes.
A lot of the code seems to be concerned with gating output (shouldOutputX), which does add a bit of complexity to existing code.
Other than that it's mostly looping over the responsive style, plus some other refactoring/supportive changes, so while a big diff, nothing really unexpected.
I think I spotted one bug when allowSwitching is enabled (mentioned in a comment).
| function gutenberg_normalize_state_style_for_css_output( $style ) { | ||
| return gutenberg_normalize_state_preset_vars( $style ); | ||
| $style = gutenberg_normalize_state_preset_vars( $style ); | ||
| unset( $style['layout'] ); |
There was a problem hiding this comment.
Could probably swap lines 46 & 47, so that gutenberg_normalize_state_preset_vars doesn't have to loop over the layout property.
| return ''; | ||
| } | ||
|
|
||
| const layoutType = getLayoutType( layout?.type || 'default' ); |
There was a problem hiding this comment.
Have we tested how it works if allowSwitching is true? In that situation, could the user set say a flex layout by default, but grid on mobile?
Here it seems like the base layout is always passed in, so I would guess it's not supported, but I'm wondering if there are UI changes needed to support that.
Edit: I tested by enabling switching on the group block, and it looks like this might be a bug. I think when a responsive state is selected, the layout type switcher could be hidden.
There was a problem hiding this comment.
I've now disabled switching when states are enabled, thanks for spotting this!
| * | ||
| * @param mixed $layout Layout object. | ||
| * @return array Child layout values, or an empty array. | ||
| */ |
There was a problem hiding this comment.
This function and the one below are necessary because in a viewport state object, both child layout and layout properties are under "layout".
This is because in the default state, "layout" contains layout properties and "style > layout" contains child layout ones. In retrospect, we might have differentiated them better from the start 😅 but not much can be done now.
|
OK I've addressed the feedback and done a bit more simplification on the PHP side.
Would it be better to leave the duplicated styles in though? |
talldan
left a comment
There was a problem hiding this comment.
Nice work, this tests well for me!
Would it be better to leave the duplicated styles in though?
I don't really have a preference, I think stick with how it is for now. 👍
What?
Part of #77817.
Adds support for setting responsive layout, block spacing and child layout styles.
Testing Instructions
Known issues: Navigation block layout styles not being applied correctly. Working on it :)
Use of AI Tools
Used gpt 5.5/codex and opus 4.7/claude