From c6b17f175f6e81c4c0a9c7bc250678c436217e3d Mon Sep 17 00:00:00 2001 From: Aaron Robertshaw <60436221+aaronrobertshaw@users.noreply.github.com> Date: Thu, 1 Oct 2026 16:38:54 +0800 Subject: [PATCH 1/2] Table: Add background gradient support --- docs/reference-guides/core-blocks/README.md | 2 +- packages/block-library/src/table/README.md | 3 +++ packages/block-library/src/table/block.json | 5 +++++ packages/block-library/src/table/edit.jsx | 9 ++++++++- packages/block-library/src/table/save.jsx | 21 ++++++++++++++++----- 5 files changed, 33 insertions(+), 7 deletions(-) diff --git a/docs/reference-guides/core-blocks/README.md b/docs/reference-guides/core-blocks/README.md index 31619b8f00a32d..5aae6f09279f55 100644 --- a/docs/reference-guides/core-blocks/README.md +++ b/docs/reference-guides/core-blocks/README.md @@ -990,7 +990,7 @@ Create structured content in rows and columns to display information. - **Name:** [core/table](https://developer.wordpress.org/block-editor/reference-guides/core-blocks/core-blocks-text/core-block-table/) - **Category:** [text](https://developer.wordpress.org/block-editor/reference-guides/core-blocks/core-blocks-text/) -- **Supports:** align, anchor, color (background, gradients, text), interactivity (clientNavigation), spacing (margin, padding), typography (fontSize, lineHeight, textAlign) +- **Supports:** align, anchor, background (gradient), color (background, gradients, text), interactivity (clientNavigation), spacing (margin, padding), typography (fontSize, lineHeight, textAlign) - **Attributes:** body, caption, foot, hasFixedLayout, head ## Table of Contents diff --git a/packages/block-library/src/table/README.md b/packages/block-library/src/table/README.md index 27987be62d3f1a..333e1303d01a38 100644 --- a/packages/block-library/src/table/README.md +++ b/packages/block-library/src/table/README.md @@ -26,6 +26,8 @@ _Defined via the [`supports`](https://developer.wordpress.org/block-editor/refer - [`anchor`](https://developer.wordpress.org/block-editor/reference-guides/block-api/block-supports/#anchor): `true` - [`align`](https://developer.wordpress.org/block-editor/reference-guides/block-api/block-supports/#align): `true` +- [`background`](https://developer.wordpress.org/block-editor/reference-guides/block-api/block-supports/#background): + - `gradient`: `true` - [`color`](https://developer.wordpress.org/block-editor/reference-guides/block-api/block-supports/#color): - [`gradients`](https://developer.wordpress.org/block-editor/reference-guides/block-api/block-supports/#color-gradients): `true` - [`spacing`](https://developer.wordpress.org/block-editor/reference-guides/block-api/block-supports/#spacing): @@ -52,6 +54,7 @@ _Defined via the [`styles`](https://developer.wordpress.org/block-editor/referen _Defined via the [`selectors`](https://developer.wordpress.org/block-editor/reference-guides/block-api/block-selectors/) property in block.json._ - **root**: `.wp-block-table > table` +- **background**: `.wp-block-table > table` - **spacing**: `.wp-block-table` ## Block Markup diff --git a/packages/block-library/src/table/block.json b/packages/block-library/src/table/block.json index 1ae82fc6ba95f2..18adf33f19586d 100644 --- a/packages/block-library/src/table/block.json +++ b/packages/block-library/src/table/block.json @@ -159,6 +159,10 @@ "supports": { "anchor": true, "align": true, + "background": { + "__experimentalSkipSerialization": true, + "gradient": true + }, "color": { "__experimentalSkipSerialization": true, "gradients": true, @@ -207,6 +211,7 @@ }, "selectors": { "root": ".wp-block-table > table", + "background": ".wp-block-table > table", "spacing": ".wp-block-table" }, "styles": [ diff --git a/packages/block-library/src/table/edit.jsx b/packages/block-library/src/table/edit.jsx index d125e698349936..a50cecb337f256 100644 --- a/packages/block-library/src/table/edit.jsx +++ b/packages/block-library/src/table/edit.jsx @@ -15,6 +15,7 @@ import { useBlockProps, __experimentalUseColorProps as useColorProps, __experimentalUseBorderProps as useBorderProps, + useBackgroundProps, useBlockEditingMode, } from '@wordpress/block-editor'; import { __, _x } from '@wordpress/i18n'; @@ -102,6 +103,7 @@ function TableEdit( { const colorProps = useColorProps( attributes ); const borderProps = useBorderProps( attributes ); + const backgroundProps = useBackgroundProps( attributes ); const textAlign = attributes?.style?.typography?.textAlign; const blockEditingMode = useBlockEditingMode(); @@ -527,6 +529,7 @@ function TableEdit( { className={ clsx( colorProps.className, borderProps.className, + backgroundProps.className, { 'has-fixed-layout': hasFixedLayout, [ `has-text-align-${ textAlign }` ]: textAlign, @@ -538,7 +541,11 @@ function TableEdit( { ), } ) } - style={ { ...colorProps.style, ...borderProps.style } } + style={ { + ...colorProps.style, + ...borderProps.style, + ...backgroundProps.style, + } } > { renderedSections } diff --git a/packages/block-library/src/table/save.jsx b/packages/block-library/src/table/save.jsx index 5472d458fd0db4..2ff6a27f41dc3e 100644 --- a/packages/block-library/src/table/save.jsx +++ b/packages/block-library/src/table/save.jsx @@ -5,6 +5,7 @@ import { __experimentalGetBorderClassesAndStyles as getBorderClassesAndStyles, __experimentalGetColorClassesAndStyles as getColorClassesAndStyles, __experimentalGetElementClassName, + getBackgroundClassesAndStyles, } from '@wordpress/block-editor'; export default function save( { attributes } ) { @@ -17,13 +18,19 @@ export default function save( { attributes } ) { const colorProps = getColorClassesAndStyles( attributes ); const borderProps = getBorderClassesAndStyles( attributes ); + const backgroundProps = getBackgroundClassesAndStyles( attributes ); const textAlign = style?.typography?.textAlign; - const classes = clsx( colorProps.className, borderProps.className, { - 'has-fixed-layout': hasFixedLayout, - [ `has-text-align-${ textAlign }` ]: textAlign, - } ); + const classes = clsx( + colorProps.className, + borderProps.className, + backgroundProps.className, + { + 'has-fixed-layout': hasFixedLayout, + [ `has-text-align-${ textAlign }` ]: textAlign, + } + ); const hasCaption = ! RichText.isEmpty( caption ); @@ -84,7 +91,11 @@ export default function save( { attributes } ) {
From bfb2f54097a3b487670aca0e62e191391fc06336 Mon Sep 17 00:00:00 2001 From: Aaron Robertshaw <60436221+aaronrobertshaw@users.noreply.github.com> Date: Fri, 9 Oct 2026 17:37:49 +0800 Subject: [PATCH 2/2] Table: Remove redundant background selector --- packages/block-library/src/table/README.md | 1 - packages/block-library/src/table/block.json | 1 - 2 files changed, 2 deletions(-) diff --git a/packages/block-library/src/table/README.md b/packages/block-library/src/table/README.md index 333e1303d01a38..86b159438027a6 100644 --- a/packages/block-library/src/table/README.md +++ b/packages/block-library/src/table/README.md @@ -54,7 +54,6 @@ _Defined via the [`styles`](https://developer.wordpress.org/block-editor/referen _Defined via the [`selectors`](https://developer.wordpress.org/block-editor/reference-guides/block-api/block-selectors/) property in block.json._ - **root**: `.wp-block-table > table` -- **background**: `.wp-block-table > table` - **spacing**: `.wp-block-table` ## Block Markup diff --git a/packages/block-library/src/table/block.json b/packages/block-library/src/table/block.json index 18adf33f19586d..c10c96ba9cafc5 100644 --- a/packages/block-library/src/table/block.json +++ b/packages/block-library/src/table/block.json @@ -211,7 +211,6 @@ }, "selectors": { "root": ".wp-block-table > table", - "background": ".wp-block-table > table", "spacing": ".wp-block-table" }, "styles": [