Block supports: add backdrop-filter with theme.json presets#77738
Block supports: add backdrop-filter with theme.json presets#77738jobthomas wants to merge 2 commits intoWordPress:trunkfrom
Conversation
Introduces backdrop-filter as a new block support, following the established shadow pattern. Adds four default presets (light, frost, heavy, vibrancy) as CSS custom properties available to all themes via Gutenberg's default theme.json. - lib/block-supports/backdrop-filter.php: PHP block support handler; outputs -webkit-backdrop-filter and backdrop-filter inline styles, registers safe_style_css filter to allow the properties through WordPress's CSS sanitization - lib/class-wp-theme-json-gutenberg.php: adds backdropFilter to PRESET_METADATA, PROPERTIES_METADATA, and VALID_SETTINGS so theme.json preset processing generates --wp--preset--backdrop-filter--* CSS vars - lib/theme.json: four default presets (light/frost/heavy/vibrancy) - packages/style-engine/src/class-wp-style-engine.php: adds backdropFilter style definition with css_vars keyed as backdrop-filter (kebab-case) to match var:preset|backdrop-filter|slug references - packages/style-engine/src/styles/backdrop-filter/index.ts: TS style engine handler - schemas/json/theme.json: schema additions for backdropFilter settings and styles Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
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. |
What does this PR do?
Introduces
backdrop-filteras a new block support, following the established pattern of theshadowsupport. Themes can now define backdrop-filter presets intheme.jsonand blocks can apply them via the style system.Addresses @jasmussen's suggestion in #64989 to first focus on theme compatibility in #64989 (comment)
Addresses this
Why is this needed?
backdrop-filteris widely used for frosted-glass and blur effects in modern UI design, and is the only major CSS visual property not yet exposed through the block supports / theme.json preset system. Without this, theme authors have no standard way to register or apply backdrop-filter values across blocks.Changes
PHP
lib/block-supports/backdrop-filter.php(new): registers thebackdropFilterblock attribute and applies it as inline CSS on the frontend. Emits bothbackdrop-filterand-webkit-backdrop-filterfor Safari ≤ 17.3 compatibility. Adds both properties to thesafe_style_cssallowlist so WordPress's CSS sanitiser doesn't strip them.lib/class-wp-theme-json-gutenberg.php: addsbackdropFiltertoPRESET_METADATA(generates--wp--preset--backdrop-filter--{slug}CSS custom properties),PROPERTIES_METADATA(mapsbackdrop-filterCSS property to thebackdropFiltertheme.json path), andVALID_SETTINGS(recognisespresetsanddefaultPresets).lib/load.php: loads the new block support file.lib/theme.json: four default presets —light(blur(6px)),frost(blur(12px) saturate(150%)),heavy(blur(24px)),vibrancy(blur(16px) saturate(180%) brightness(1.05)).Style engine (PHP)
packages/style-engine/src/class-wp-style-engine.php: adds abackdropFilterstyle definition. Thecss_varskey uses the kebab-case string'backdrop-filter'to correctly resolvevar:preset|backdrop-filter|{slug}references.Style engine (TypeScript)
packages/style-engine/src/styles/backdrop-filter/index.ts(new): TypeScript style handler usinggenerateRule.packages/style-engine/src/styles/index.ts: exports the new handler.Schema & docs
schemas/json/theme.json:settingsBackdropFilterPropertiesdefinition, added tosettingsPropertiesallOf,settingsPropertyNamesenum, stylesbackdropFilterproperty,stylesPropertyNamesenum.docs/reference-guides/theme-json-reference/theme-json-living.md: auto-generated vianpm run docs:build.How to test
CSS custom properties are generated — open any frontend page and run in the browser console:
Repeat for slugs
light,heavy, andvibrancy.Preset reference resolves — on a block with
backdropFiltersupport, setstyle.backdropFiltertovar:preset|backdrop-filter|frostand confirm the rendered inline style containsbackdrop-filter:var(--wp--preset--backdrop-filter--frost).Raw value passthrough — set
style.backdropFiltertoblur(8px)and confirm the rendered inline style is-webkit-backdrop-filter:blur(8px);backdrop-filter:blur(8px);.safe_style_cssallowlist — confirm neitherbackdrop-filternor-webkit-backdrop-filteris stripped by WordPress's CSS sanitiser.defaultPresets: falsesuppresses presets — add"settings": { "backdropFilter": { "defaultPresets": false } }to a child theme'stheme.jsonand confirm the four default--wp--preset--backdrop-filter--*variables no longer appear in the page<style>block.Notes
"backdropFilter": trueto individualblock.jsonfiles and the JS editor panel for the preset picker) is a follow-up. This PR establishes the infrastructure: CSS vars, style engine resolution, and the PHP block support handler.-webkit-backdrop-filterprefix is emitted for Safari ≤ 17.3 compatibility, matching the approach used by other properties in this codebase.Follows
This follows the pattern established by the
shadowblock support (lib/block-supports/shadow.php).