-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Block visibility supports: implement block visibility based on breakpoints #10629
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
base: trunk
Are you sure you want to change the base?
Block visibility supports: implement block visibility based on breakpoints #10629
Conversation
|
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 Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
bf1d22c to
2835818
Compare
| * Breakpoints as array items are defined sequentially. The first item's size is the max value. | ||
| * Each subsequent item's min is calc(previous size + 1px), and its size is the max. | ||
| * The last item's min is previous size plus 1px, and it has no max. |
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.
Can we avoid the 1px offset and instead use the range syntax for media queries? We switched to this in Performance Lab, as it addresses possible issues with media queries in sub-pixel scenarios: WordPress/performance#1696
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 bringing that up @westonruter
I forgot about range - looks like it has decent support now.
What do you think @tellthemachines ?
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.
looks like it has decent support now
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.
Yes absolutely, let's give it a go!
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 folks, I'll make a start on this 🙇🏻
| * Breakpoints as array items are defined sequentially. The first item's size is the max value. | ||
| * Each subsequent item's min is calc(previous size + 1px), and its size is the max. | ||
| * The last item's min is previous size plus 1px, and it has no max. |
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 bringing that up @westonruter
I forgot about range - looks like it has decent support now.
What do you think @tellthemachines ?
| * Each subsequent item's min is calc(previous size + 1px), and its size is the max. | ||
| * The last item's min is previous size plus 1px, and it has no max. | ||
| */ | ||
| $breakpoints = array( |
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 wanted to also mention this idea raised by @t-hamano
This is a technical question, but in the future, how do you think about being able to hide blocks based on sources other than screen size (e.g. user role, time period)? If there's a chance that there could be multiple sources, it might be better to nest the metadata key for now,
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.
Done in WordPress/gutenberg#74602
928a9eb to
2190cc5
Compare
…implement block visibility based on breakpoints. This update introduces the `display` property to the `safecss_filter_attr` function, enhancing CSS filtering capabilities. Additionally, it implements breakpoint visibility support in block rendering, allowing blocks to be hidden or shown based on defined breakpoints. Corresponding tests have been added to ensure functionality. See #64414.
…ty when all visibility breakpoints (mobile, tablet, desktop) are set to false.
…heet retrieval. This change ensures that the generated styles for mobile, tablet, and desktop breakpoints are returned without additional formatting, allowing for accurate assertions in the tests.
…ign with design specifications. Adjust corresponding unit tests to reflect the new breakpoint values.
…mproved clarity. Update unit tests to reflect changes in breakpoint definitions for mobile, tablet, and desktop visibility rules.
…date media query generation to ensure accurate handling of viewport sizes.
b2b2ff4 to
0ca2322
Compare
Note
The feature is still in an experiment in Gutenberg, so this PR is a placeholder for stabilization. See: WordPress/gutenberg#73994
This PR syncs the changes in WordPress/gutenberg#73994. It:
displayproperty to thesafecss_filter_attrfunction.Unit tests:
Then copy and paste this into your post editor, publish and view the frontend.
Kapture.2025-12-14.at.19.37.29.mp4
Make sure to test with the experiment off as well. The last item should never show with the experiment on and off.
Trac ticket: https://core.trac.wordpress.org/ticket/64414