Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/reference-guides/core-blocks/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions packages/block-library/src/table/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
4 changes: 4 additions & 0 deletions packages/block-library/src/table/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,10 @@
"supports": {
"anchor": true,
"align": true,
"background": {
"__experimentalSkipSerialization": true,
"gradient": true
},
"color": {
"__experimentalSkipSerialization": true,
"gradients": true,
Expand Down
9 changes: 8 additions & 1 deletion packages/block-library/src/table/edit.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
useBlockProps,
__experimentalUseColorProps as useColorProps,
__experimentalUseBorderProps as useBorderProps,
useBackgroundProps,
useBlockEditingMode,
} from '@wordpress/block-editor';
import { __, _x } from '@wordpress/i18n';
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -527,6 +529,7 @@ function TableEdit( {
className={ clsx(
colorProps.className,
borderProps.className,
backgroundProps.className,
{
'has-fixed-layout': hasFixedLayout,
[ `has-text-align-${ textAlign }` ]: textAlign,
Expand All @@ -538,7 +541,11 @@ function TableEdit( {
),
}
) }
style={ { ...colorProps.style, ...borderProps.style } }
style={ {
...colorProps.style,
...borderProps.style,
...backgroundProps.style,
} }
>
{ renderedSections }
</table>
Expand Down
21 changes: 16 additions & 5 deletions packages/block-library/src/table/save.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
__experimentalGetBorderClassesAndStyles as getBorderClassesAndStyles,
__experimentalGetColorClassesAndStyles as getColorClassesAndStyles,
__experimentalGetElementClassName,
getBackgroundClassesAndStyles,
} from '@wordpress/block-editor';

export default function save( { attributes } ) {
Expand All @@ -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 );

Expand Down Expand Up @@ -84,7 +91,11 @@ export default function save( { attributes } ) {
<figure { ...useBlockProps.save() }>
<table
className={ classes === '' ? undefined : classes }
style={ { ...colorProps.style, ...borderProps.style } }
style={ {
...colorProps.style,
...borderProps.style,
...backgroundProps.style,
} }
>
<Section type="head" rows={ head } />
<Section type="body" rows={ body } />
Expand Down
Loading