-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Table Block: Fix margin/padding to include caption in spacing #68281
Table Block: Fix margin/padding to include caption in spacing #68281
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 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. |
Hi @Infinite-Null, thanks for the PR ✨ I've tested out the PR and it seems to work as expected. The bug has been resolved. |
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 the PR!
One thing to be aware of is that the __experimentalSelector
field affects all global styles. Other styles, except padding/margin, etc. are expected to apply to the table
element, but in this PR they are applied to the figure
element, which is not the intention.
Below is a screenshot of the border, color, and font styles applied to the Table block via the global styles:
trunk
This PR
Therefore, we cannot modify the __experimentalSelector
field directly.
Instead, there is now a new Block Selectors API. Can we use this to target spacing support to figure elements and other elements to table elements as before?
Hi @t-hamano, Thank you for the suggestion. I’ve reverted the __experimentalSelector and applied the following to address the issue:
Please review it at your convenience. |
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 the update!
Sorry, my explanation was insufficient. The problem is that padding is applied to the table
element, resulting in space between the table
and the caption
. I think what is expected here is that both padding and margin are applied to the figure
element, just like with block instances.
"selectors": {
"spacing": {
"margin": ".wp-block-table"
}
},
Therefore, the above code alone is not sufficient.
Furthermore, it would be a good idea to delete the __experimentalSelector
field and aggregate it into the selectors
field.
Considering these things, the following definition should work fine:
"selectors": {
"root": ".wp-block-table > table",
"spacing": ".wp-block-table"
},
Hi @t-hamano, |
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.
LGTM! I tested it using the following theme.json:
Details
{
"$schema": "../../schemas/json/theme.json",
"version": 3,
"settings": {
"appearanceTools": true,
"layout": {
"contentSize": "840px",
"wideSize": "1100px"
}
},
"styles": {
"blocks": {
"core/table": {
"color": {
"text": "green",
"background": "#ccc"
},
"border": {
"width": "5px",
"style": "dashed",
"color": "#000"
},
"typography": {
"fontSize": "20px",
"fontWeight": "bold",
"textTransform": "uppercase",
"textDecoration": "underline"
},
"spacing": {
"padding": {
"top": "60px",
"bottom": "60px"
},
"margin": {
"top": "60px",
"bottom": "60px"
}
}
}
}
}
}
- ✅ Padding and margin are applied to the
figure
element. All other styles are applied to thetable
element. - ✅ Styles applied in the Global Styles UI correctly override styles defined in theme.json.
- Block instance styles correctly override styles applied in the Global Styles UI.
By the way, while reviewing this PR, I noticed that block instances cannot override typography styles applied in theme.json or global styles.
This is not a blocker because it occurs in trunk. I will merge this PR and then submit the issue.
Fixes: #68217
What?
The PR modifies the margin application in table blocks to ensure theme.json margin settings are applied to the figure wrapper instead of the inner table element.
Why?
When margins are set via theme.json, they are applied to the inner table element, causing undesirable spacing between the table and its caption. This PR fixes these spacing inconsistencies by applying margins to the correct element.
Testing Instructions
Screenshots or screencast