-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Layout: use CSS logical properties for margin top and bottom #38816
Conversation
Size Change: +3 B (0%) Total Size: 1.16 MB
ℹ️ View Unchanged
|
In my projects, I've been using an implementation of this in my own overrides of the Render Layout Support portion of the block supports API for months now across about a dozen or so production FSE sites in the wild and they've all worked flawlessly. It's implementation makes sense because:
|
112dce8
to
149a2c8
Compare
e598999
to
e242394
Compare
$has_block_gap_support = _wp_array_get( $this->theme_json, array( 'settings', 'spacing', 'blockGap' ) ) !== null; | ||
if ( $has_block_gap_support ) { | ||
$block_rules .= '.wp-site-blocks > * { margin-block-start: 0; margin-block-end: 0; }'; | ||
$block_rules .= '.wp-site-blocks > * + * { margin-block-start: var( --wp--style--block-gap ); }'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method was imported to redefine these styles.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for working on this @ramonjd, this looks like a good path forward for supporting different languages and writing modes in our layout supports 👍
I couldn't find any issues immediately with this PR applied, except that when I switched writing-mode: vertical-rl
on within the front end of my site running TT2, the margins then behave differently to how I'd expect. While the paragraphs and spacing rendered correctly in a vertical layout, the horizontal margins that were aligning the block centred in the page, now cause the block to display at the left side of the page:
Before applying writing mode | After applying writing mode |
---|---|
Did you encounter anything like that in your testing? I manually applied the CSS property in Dev Tools to the group block.
Update: I think that's because of margin-block-start
and margin-block-end
being set to 0
in the vertical writing mode. If they're auto
then I can get it centred again?
So I wonder if there's a limit to how many of the rules we want to be logical (and in which circumstances), versus physical? E.g. in vertical writing mode, how much of the layout do we want it to automatically change?
Thanks for testing @andrewserong and for pointing out the inconsistency there. This one was always going to be cutting edge, given that there's no immediate requirement for CSS logical properties and seeing as we don't officially support It was really meant as a stepping stone towards getting full support if we ever refactor layout, and also to set theme authors on an easier path to their own writing mode implementations.
This makes sense to me. I didn't see this when testing, but I agree it's a bit strange. I'll have another look to try and get it working more intuitively. Thanks again! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just want to say that this makes sense to me, and the code (JS/CSS) looks good too!
…t-to-right, vertical and so on. With CSS logical properties, block and inline margins will apply to the appropriate side depending on the direction of the document flow. This change to the layout margins ensures that margins will adhere to the logic of current flow. For example, margin-block-start (instead of margin-top) will manifest itself as a top margin for `writing-mode: horizontal-tb;` but a right margin for `writing-mode: vertical-rl;`.
…ht. Other minor formatting Taking a clumsy stab at compat files so we can load the global styles and settings.
Removing `get_stylesheet()` from WP_Theme_JSON_Gutenberg
…l page layout (left and right margins) so that any changes to the writing mode of blocks within wp-site-blocks and block containers still align themselves according to current horizontal rules.
f9acb32
to
0616be3
Compare
Thanks for testing @kevin940726 !
@andrewserong The PR is now limited to swapping The right and left values I've left alone to preserve centered layouts even in alternative writing-modes. I've rebased and tested the changes again. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@andrewserong The PR is now limited to swapping margin-top and margin-bottom for margin-block-start and margin-block-end respectively.
Thanks for the ping @ramonjd! Yes, that's fixed it up for me so the centered styling is preserved now in testing:
I've given this a re-test with a few different blocks, and tested in TT2 and looked for regressions in TT1 and TwentyTwenty themes, and couldn't find any issues 🙂
This LGTM, and we can always look into follow-ups if needed for #38319 down the track!
…ECTOR` made it in. It should be static to retain the inheritance powers introduced in #38671
…ECTOR` made it in. It should be static to retain the inheritance powers introduced in #38671
Depends on
Description
The layout implementation doesn't take into account different writing modes, such as left-to-right, vertical and so on.
With CSS logical properties, block and inline margins will apply to the appropriate side of an element depending on the direction of the document flow.
This change to the layout margins ensures that margins will adhere to the logic of the current flow.
Related PR:
For example, margin-block-start (instead of margin-top) will manifest itself as a top margin for
writing-mode: horizontal-tb;
but a right margin forwriting-mode: vertical-rl;
.With writing-mode: horizontal-tb;
With writing-mode: vertical-rl;
Trunk:
This branch:
TODO
Why do this?
As mentioned over at #38694 (comment), this change will make it easier for theme authors to style block content using alternative
writing-mode
s.Testing Instructions
Test both in WordPress 5.8 and WordPress 5.9.
Open the editor and add a group block with several children. Here is some test code:
Test block code
Play around with the gap value, then publish the post and take a squiz at the frontend.
Check that the gap values between the group's child elements (margin top) appear as expected.
Using the browser inspector, add
writing-mode: vertical-rl;
to the group container div.Check that the gap values between the group's child elements (logical margin top (right)) appear as expected.
Use a theme that opts into
blockGap
such as TwentyTwentyTwo.Check that the gap between site blocks are uneffected.
For block themes,
.wp-site-blocks
should have an inline class ofwp-site-blocks > * + * { margin-block-start: var( --wp--style--block-gap );
Run the tests!
Types of changes
CSS enhancement. Future compatibility.
Checklist:
*.native.js
files for terms that need renaming or removal).