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

Fix: :root no longer causes invalid selectors #13325

Merged
merged 1 commit into from
Jan 22, 2019
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
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,9 @@ exports[`CSS selector wrap should wrap regular selectors 1`] = `
color: red;
}"
`;

exports[`CSS selector wrap should replace :root selectors 1`] = `
".my-namespace {
--my-color: #ff0000;
}"
`;
11 changes: 11 additions & 0 deletions packages/editor/src/editor-styles/transforms/test/wrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,15 @@ describe( 'CSS selector wrap', () => {

expect( output ).toMatchSnapshot();
} );

it( 'should replace :root selectors', () => {
const callback = wrap( '.my-namespace' );
const input = `
:root {
--my-color: #ff0000;
}`;
const output = traverse( input, callback );

expect( output ).toMatchSnapshot();
} );
} );
4 changes: 2 additions & 2 deletions 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 @@ -20,7 +20,7 @@ const wrap = ( namespace, ignore = [] ) => ( node ) => {
}}

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

if ( node.type === 'rule' ) {
Expand Down