-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Improve cover z-index solution #66249
base: trunk
Are you sure you want to change the base?
Improve cover z-index solution #66249
Conversation
So we don't need to set z-index in all the elements, creating the stacking context for the inner blocks, for example.
".wp-block-cover.has-background-dim::before": 1, // Overlay area inside block cover need to be higher than the video background. | ||
".block-library-cover__padding-visualizer": 2, // BoxControl visualizer needs to be +1 higher than .wp-block-cover.has-background-dim::before |
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.
@@ -88,7 +88,8 @@ export default function save( { attributes } ) { | |||
'has-custom-content-position': | |||
! isContentPositionCenter( contentPosition ), | |||
}, | |||
getPositionClassName( contentPosition ) | |||
getPositionClassName( contentPosition ), | |||
'has-no-zindex-in-inner-blocks' |
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.
I didn't like this name, but I couldn't find a better one. I though about a has-natural-elements-order
or something like this, but the has-no-zindex-in-inner-blocks
seems more self-explanatory about the purpose of this.
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.
Could we avoid the introduction of the CSS class entirely using sibling CSS selectors?
This would also mean that only blocks with both an overlay and media background would need the reordered markup, reducing the number of blocks requiring a migration via the deprecation.
cccb26d
to
e9c5f0b
Compare
z-index: auto; | ||
&.has-no-zindex-in-inner-blocks { | ||
.wp-block-cover__inner-container { | ||
position: relative; // It needs a position to be on top of the other elements. |
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.
Please, look at this property with a grain of salt. I think it won't cause any issue, but if we had an element inside this block with a position absolute, it would be affected.
The next block in the tree with the position relative would be the immediate parent (.wp-block-cover
). I don't believe we would have an existing think trusting in the position relative to the .wp-block-cover
, but we never know! =P
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.
After a quick glance it seems okay. Once the deprecation and styles are iterated on we can test this aspect after they've settled.
Warning: Type of PR label mismatch To merge this PR, it requires exactly 1 label indicating the type of PR. Other labels are optional and not being checked here.
Read more about Type labels in Gutenberg. Don't worry if you don't have the required permissions to add labels; the PR reviewer should be able to help with the task. |
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. |
I'm already opening it for review, but it still has some test issues. I tried to update the fixtures through |
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.
Thank you for following up on #66093 @renatho 👍
I've taken this for a test drive. It's coming together well but I did run into a few issues.
✅ Cover z-index behaviour works as expected post migration
✅ Deprecated blocks appear to migrate in the editor
✅ Deprecated blocks still render appropriately on the frontend
❌ After saving the post and reloading, the deprecated blocks don't appear to have been migrated i.e. they retrigger the deprecation. Making an unrelated edit and resaving the post seems to apply the updates the second time around.
Screen.Recording.2024-10-21.at.3.06.58.pm.mp4
In addition to the migration issue flagged above, I've left a few other thoughts as inline comments where applicable.
These include:
- We should be able to avoid introducing the new CSS class to the markup by using CSS sibling selectors for both the latest and BC styles.
- This would also mean that less blocks would need to be migrated, perhaps mitigating a tiny bit of the performance hit.
- i.e. only blocks with both the color overlay and an image or video would have their markup changed requiring a migration.
- As the original fix is slated for release in 19.6, we could avoid the need to include styles for
.has-modal-open
for BC reasons.- I understand the consistency argument but simply including it for no functional reason and setting a precedent for a block in the editor to mess with the document root classes feels like a stretch.
- Happy to hear others' thoughts on that one. My vote is remove it, we can always add it when there is a pressing need.
- We need a new fixture to cover this latest deprecation.
- All the non-deprecation-related fixtures for the cover block need to be updated to the latest markup structure.
- This is why the fixture regeneration is throwing the error around an unexpected deprecation being run.
- After the above fixture updates, regenerating the fixtures should succeed and the result should be something like past deprecation's serialized HTML being updated to the correct structure.
I suspect that in the process of ironing out the deprecation, the bug I noticed while testing will be uncovered and resolved 🤞
@renatho let me know if anything around my recommendations for the deprecation tweaks isn't clear.
.wp-block-cover:not(.has-no-zindex-in-inner-blocks) { // Shown while media is being uploaded | ||
.components-spinner { | ||
z-index: z-index(".wp-block-cover__inner-container"); | ||
} | ||
} |
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.
Do we need to scope this by the proposed CSS class? The old spinner style would result in the same z-index as the inner container, which comes later in the DOM.
At a quick glance, the positioning of the spinner before the inner container is the same on trunk and this PR. In both cases the spinner is rendered beneath the inner container.
@@ -88,7 +88,8 @@ export default function save( { attributes } ) { | |||
'has-custom-content-position': | |||
! isContentPositionCenter( contentPosition ), | |||
}, | |||
getPositionClassName( contentPosition ) | |||
getPositionClassName( contentPosition ), | |||
'has-no-zindex-in-inner-blocks' |
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.
Could we avoid the introduction of the CSS class entirely using sibling CSS selectors?
This would also mean that only blocks with both an overlay and media background would need the reordered markup, reducing the number of blocks requiring a migration via the deprecation.
@@ -302,3 +292,32 @@ section.wp-block-cover-image > h2, | |||
color: inherit; | |||
} | |||
} | |||
|
|||
// Backward compatibility for v14 deprecation. | |||
.wp-block-cover:not(.has-no-zindex-in-inner-blocks) { |
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.
As noted in the above thread, it could be possible to avoiding needing .has-no-zindex-in-inner-blocks
completely.
// Reset the z-index to auto when the body has a modal open. So when the | ||
// modal is inside the cover, it doesn't create a stacking context. | ||
@at-root .has-modal-open & { | ||
z-index: auto; | ||
} |
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.
If #66093 isn't slated for release until 19.6, could we also avoid these additional styles? I don't think we need to provide BC for a change that hasn't been released yet.
@@ -244,6 +244,157 @@ const v12BlockSupports = { | |||
}, | |||
}; | |||
|
|||
// Deprecation for blocks that have z-index. | |||
const v14 = { |
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 deprecation will need a fixture to cover it. Here's an example for an earlier deprecation.
What?
This is an improved solution for this original PR: #66093
As part of this PR, I also thought of removing this effect that adds the
has-modal-open
in the editor because that wouldn't be needed for this purpose anymore. But thinking more, I kept it to keep the consistency there between the frontend and the editor.Why?
To improve the solution and eliminate the dependencies between Cover and Navigation blocks (the class that Navigation adds being used in the Cover styles).
More context starting from this comment in the thread.
How?
It deprecates the current version of the Cover block, changing the order of the elements, and removing the
z-index
of them.It continues using the
has-modal-open
class for backward compatibility (solution introduced in #66093), but when the code is updated it's not used anymore (after the save).Testing Instructions
Screenshots or screencast
Screen.Recording.2024-10-14.at.11.28.51.mp4
Since I continued seeing the same result in my tests, I reused the same video from #66093 just to illustrate the tests.