-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Fix : Calendar block: Colors do not change between global styles and theme.json
#70184
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
Fix : Calendar block: Colors do not change between global styles and theme.json
#70184
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. |
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!
This PR certainly solves the symptom, but I think the underlying problem needs to be addressed.
Specifically, lower the CSS specificity of the calendar block's default styles from 0-1-1
to 0-1-0
to allow global styles to properly override the calendar block's styles (See #69896 (comment) for more details.).
In my testing, the following changes seem to work ideally:
diff --git a/packages/block-library/src/calendar/style.scss b/packages/block-library/src/calendar/style.scss
index 969d1aafec..5e2db8da95 100644
--- a/packages/block-library/src/calendar/style.scss
+++ b/packages/block-library/src/calendar/style.scss
@@ -19,16 +19,6 @@
width: 100%;
border-collapse: collapse;
- &:where(:not(.has-text-color)) {
- color: #40464d;
-
- // Keep the hard-coded border color for backward compatibility.
- th,
- td {
- border-color: $gray-300;
- }
- }
-
&.has-background th {
background-color: inherit;
}
@@ -37,6 +27,16 @@
color: inherit;
}
}
+
+ :where(table:not(.has-text-color)) {
+ color: #40464d;
+
+ // Keep the hard-coded border color for backward compatibility.
+ th,
+ td {
+ border-color: $gray-300;
+ }
+ }
}
// Keep the hard-coded header background color for backward compatibility.
Let me know if this approach works for you.
Also, important things to test are:
- Can change text color, background color, and link via the global styles
- Can override them individually from block instances.
Hi @t-hamano, thanks for your feedback.
calendar.mp4Let me know if this works. Thank |
Sorry, I didn't explain it well enough. The changes I proposed were made to the trunk branch, not to this PR. So even if we remove the code you added, it should work as expected. |
Hi @t-hamano, when i remove the other changes I've implemented the manual block styles the user may apply won't be applied correctly. Here's a screencast for the displaying the effect fix.mp4 |
Can you check again? We only need to change the CSS in the trunk branch. The Details.wp-block-calendar {
text-align: center;
th,
td {
padding: 0.25em;
border: 1px solid;
}
th {
font-weight: 400;
}
caption {
background-color: inherit;
}
table {
width: 100%;
border-collapse: collapse;
&.has-background th {
background-color: inherit;
}
&.has-text-color th {
color: inherit;
}
}
&:where(:not(.has-text-color)) {
color: #40464d;
// Keep the hard-coded border color for backward compatibility.
th,
td {
border-color: $gray-300;
}
}
}
// Keep the hard-coded header background color for backward compatibility.
:where(.wp-block-calendar table:not(.has-background) th) {
background: $gray-300;
} |
Hi @t-hamano I replace the entire file content with the copy you shared and these were the results
We need to inherit the colors for the background of |
@Vrishabhsk Did you change the value of Will anything go wrong if we don't update |
Hi @t-hamano, After reverting the |
@Vrishabhsk Thanks for the update! Sorry, the code I suggested was incorrect. I think the ideal code would be the one in this comment, which means I think the following changes are needed: diff --git a/packages/block-library/src/calendar/style.scss b/packages/block-library/src/calendar/style.scss
index cac3c0e1c6..5e2db8da95 100644
--- a/packages/block-library/src/calendar/style.scss
+++ b/packages/block-library/src/calendar/style.scss
@@ -28,7 +28,7 @@
}
}
- &:where(:not(.has-text-color)) {
+ :where(table:not(.has-text-color)) {
color: #40464d;
// Keep the hard-coded border color for backward compatibility. Can you test this code to see if it works? |
Hi @t-hamano, the above suggested change also works as expected. I have updated the selector. Thanks |
…`theme.json` (WordPress#70184) * Add styles and update selectors * Update styles as per recommendation * Revert unnecessary selectors and styles * Update selector Co-authored-by: Vrishabhsk <vrishabhsk@git.wordpress.org> Co-authored-by: t-hamano <wildworks@git.wordpress.org> Co-authored-by: Infinite-Null <ankitkumarshah@git.wordpress.org> Co-authored-by: shimotmk <shimotomoki@git.wordpress.org>
What?
theme.json
#69896Why?
How?
__experimentalSelector
attribute for color support to includetd
andcaption
text color
if set via theEditor
else pick thecolor
set viatheme.json
Testing Instructions
styles ➡ blocks
Screenshots or screencast