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/editor styles wrap #11957

Closed
wants to merge 2 commits into from
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ opacity: 0;

exports[`CSS selector wrap should ignore selectors 1`] = `
".my-namespace h1,
.my-namespace:not(EDITOR_STYLES),
body {
color: red;
}"
Expand Down
2 changes: 1 addition & 1 deletion packages/editor/src/editor-styles/transforms/test/wrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ describe( 'CSS selector wrap', () => {

it( 'should ignore selectors', () => {
const callback = wrap( '.my-namespace', 'body' );
const input = `h1, body { color: red; }`;
const input = `h1, :root, body { color: red; }`;
const output = traverse( input, callback );

expect( output ).toMatchSnapshot();
Expand Down
8 changes: 7 additions & 1 deletion packages/editor/src/editor-styles/transforms/wrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { includes } from 'lodash';
/**
* @const string IS_ROOT_TAG Regex to check if the selector is a root tag selector.
*/
const IS_ROOT_TAG = /^(body|html).*$/;
const IS_ROOT_TAG = /^(body|html|:root).*$/;

const wrap = ( namespace, ignore = [] ) => ( node ) => {
const updateSelector = ( selector ) => {
Expand All @@ -19,6 +19,12 @@ const wrap = ( namespace, ignore = [] ) => ( node ) => {
return namespace + ' ' + selector;
}}

// If explicity :root selector namespace with pseudo to respect original specificity intended on namespace.
if ( ':root' === selector.trim() ) {
// We use an invalid negation to inherit the negation's :pseudo specificity weight applied on namespace.
return selector.replace( ':root', `${ namespace }:not(EDITOR_STYLES)` );
}

// HTML and Body elements cannot be contained within our container so lets extract their styles.
return selector.replace( /^(body|html)/, namespace );
};
Expand Down