Skip to content
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

Update: Target global styles to the body element instead of :root #31302

Merged
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
12 changes: 6 additions & 6 deletions docs/how-to-guides/themes/theme-json.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ To address this need, we've started to experiment with CSS Custom Properties, ak
{% Output %}

```css
:root {
body {
--wp--preset--color--black: #000000;
--wp--preset--color--white: #ffffff;
}
Expand Down Expand Up @@ -122,7 +122,7 @@ To address this need, we've started to experiment with CSS Custom Properties, ak
{% Output %}

```css
:root {
body {
--wp--custom--line-height--body: 1.7;
--wp--custom--line-height--heading: 1.3;
}
Expand Down Expand Up @@ -292,7 +292,7 @@ For example:
{% Output %}

```css
:root {
body {
--wp--preset--color--strong-magenta: #a156b4;
--wp--preset--color--very-dark-gray: #444;
--wp--preset--font-size--big: 32;
Expand Down Expand Up @@ -344,7 +344,7 @@ For example:
{% Output %}

```css
:root {
body {
--wp--custom--base-font: 16;
--wp--custom--line-height--small: 1.2;
--wp--custom--line-height--medium: 1.4;
Expand Down Expand Up @@ -434,7 +434,7 @@ For example:
{% Output %}

```css
:root {
body {
color: var( --wp--preset--color--primary );
}
h1 {
Expand Down Expand Up @@ -549,7 +549,7 @@ For example:
{% Output %}

```css
:root {
body {
--wp--custom--line-height--body: 1.7;
--wp--custom--font-primary: "-apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen-Sans, Ubuntu, Cantarell, 'Helvetica Neue', sans-serif";
}
Expand Down
6 changes: 3 additions & 3 deletions lib/class-wp-theme-json.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class WP_Theme_JSON {
*
* @var string
*/
const ALL_BLOCKS_SELECTOR = ':root';
const ALL_BLOCKS_SELECTOR = 'body';

/**
* How to address the root block
Expand All @@ -54,7 +54,7 @@ class WP_Theme_JSON {
*
* @var string
*/
const ROOT_BLOCK_SELECTOR = ':root';
const ROOT_BLOCK_SELECTOR = 'body';

const VALID_TOP_LEVEL_KEYS = array(
'customTemplates',
Expand Down Expand Up @@ -356,7 +356,7 @@ private static function to_property( $css_name ) {
*
* {
* 'root': {
* 'selector': ':root'
* 'selector': 'body'
* },
* 'core/heading/h1': {
* 'selector': 'h1'
Expand Down
4 changes: 2 additions & 2 deletions packages/edit-site/src/components/editor/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ import { store as editSiteStore } from '../../store';

/* Supporting data */
export const ALL_BLOCKS_NAME = 'defaults';
export const ALL_BLOCKS_SELECTOR = ':root';
export const ALL_BLOCKS_SELECTOR = 'body';
export const ROOT_BLOCK_NAME = 'root';
export const ROOT_BLOCK_SELECTOR = ':root';
export const ROOT_BLOCK_SELECTOR = 'body';
export const ROOT_BLOCK_SUPPORTS = [
'--wp--style--color--link',
'background',
Expand Down
8 changes: 4 additions & 4 deletions phpunit/class-wp-theme-json-test.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,15 +108,15 @@ function test_get_stylesheet() {
);

$this->assertEquals(
':root{--wp--preset--color--grey: grey;--wp--preset--font-family--small: 14px;--wp--preset--font-family--big: 41px;}.wp-block-group{--wp--custom--base-font: 16;--wp--custom--line-height--small: 1.2;--wp--custom--line-height--medium: 1.4;--wp--custom--line-height--large: 1.8;}:root{--wp--style--color--link: #111;color: var(--wp--preset--color--grey);}.wp-block-group{padding-top: 12px;padding-bottom: 24px;}.has-grey-color{color: grey !important;}.has-grey-background-color{background-color: grey !important;}.has-grey-border-color{border-color: grey !important;}',
'body{--wp--preset--color--grey: grey;--wp--preset--font-family--small: 14px;--wp--preset--font-family--big: 41px;}.wp-block-group{--wp--custom--base-font: 16;--wp--custom--line-height--small: 1.2;--wp--custom--line-height--medium: 1.4;--wp--custom--line-height--large: 1.8;}body{--wp--style--color--link: #111;color: var(--wp--preset--color--grey);}.wp-block-group{padding-top: 12px;padding-bottom: 24px;}.has-grey-color{color: grey !important;}.has-grey-background-color{background-color: grey !important;}.has-grey-border-color{border-color: grey !important;}',
$theme_json->get_stylesheet()
);
$this->assertEquals(
':root{--wp--style--color--link: #111;color: var(--wp--preset--color--grey);}.wp-block-group{padding-top: 12px;padding-bottom: 24px;}.has-grey-color{color: grey !important;}.has-grey-background-color{background-color: grey !important;}.has-grey-border-color{border-color: grey !important;}',
'body{--wp--style--color--link: #111;color: var(--wp--preset--color--grey);}.wp-block-group{padding-top: 12px;padding-bottom: 24px;}.has-grey-color{color: grey !important;}.has-grey-background-color{background-color: grey !important;}.has-grey-border-color{border-color: grey !important;}',
$theme_json->get_stylesheet( 'block_styles' )
);
$this->assertEquals(
':root{--wp--preset--color--grey: grey;--wp--preset--font-family--small: 14px;--wp--preset--font-family--big: 41px;}.wp-block-group{--wp--custom--base-font: 16;--wp--custom--line-height--small: 1.2;--wp--custom--line-height--medium: 1.4;--wp--custom--line-height--large: 1.8;}',
'body{--wp--preset--color--grey: grey;--wp--preset--font-family--small: 14px;--wp--preset--font-family--big: 41px;}.wp-block-group{--wp--custom--base-font: 16;--wp--custom--line-height--small: 1.2;--wp--custom--line-height--medium: 1.4;--wp--custom--line-height--large: 1.8;}',
$theme_json->get_stylesheet( 'css_variables' )
);
}
Expand Down Expand Up @@ -187,7 +187,7 @@ public function test_get_stylesheet_preset_values_are_marked_as_important() {
);

$this->assertEquals(
':root{--wp--preset--color--grey: grey;}h2.wp-block-post-title{background-color: blue;color: red;font-size: 12px;line-height: 1.3;}.has-grey-color{color: grey !important;}.has-grey-background-color{background-color: grey !important;}.has-grey-border-color{border-color: grey !important;}',
'body{--wp--preset--color--grey: grey;}h2.wp-block-post-title{background-color: blue;color: red;font-size: 12px;line-height: 1.3;}.has-grey-color{color: grey !important;}.has-grey-background-color{background-color: grey !important;}.has-grey-border-color{border-color: grey !important;}',
$theme_json->get_stylesheet()
);
}
Expand Down