File tree Expand file tree Collapse file tree 2 files changed +14
-6
lines changed
Expand file tree Collapse file tree 2 files changed +14
-6
lines changed Original file line number Diff line number Diff line change @@ -20,6 +20,7 @@ describe('Selector', () => {
2020 test ( 'creates selector for context' , ( ) => {
2121 expect ( selector . for ( { global : [ '.theme' ] , local : [ '.context' ] } ) ) . toEqual ( '.theme .context' ) ;
2222 expect ( selector . for ( { global : [ ':root' ] , local : [ '.context' ] } ) ) . toEqual ( '.context' ) ;
23+ expect ( selector . for ( { global : [ 'html' , '.theme' ] , local : [ '.context' ] } ) ) . toEqual ( '.theme .context' ) ;
2324 } ) ;
2425
2526 test ( 'creates selector for context within mode' , ( ) => {
@@ -34,4 +35,10 @@ describe('Selector', () => {
3435 const selector = new Selector ( ( sel ) => `${ sel } :not(.theme)` ) ;
3536 expect ( selector . for ( { global : [ ':root' , '.mode' ] , local : [ '.context' ] } ) ) . toEqual ( '.mode .context:not(.theme)' ) ;
3637 } ) ;
37- } ) ;
38+
39+ test ( 'applies global selectors alone when no local selectors' , ( ) => {
40+ expect ( selector . for ( { global : [ ':root' ] } ) ) . toEqual ( ':root' ) ;
41+ expect ( selector . for ( { global : [ 'body' ] } ) ) . toEqual ( 'body' ) ;
42+ expect ( selector . for ( { global : [ 'html' ] } ) ) . toEqual ( 'html' ) ;
43+ } ) ;
44+ } ) ;
Original file line number Diff line number Diff line change 11// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
22// SPDX-License-Identifier: Apache-2.0
33import type { SelectorCustomizer } from './interfaces' ;
4+ import { isGlobalSelector } from '../styles/selector' ;
45
56interface SelectorParams {
67 global : string [ ] ;
@@ -15,13 +16,13 @@ export class Selector {
1516 }
1617
1718 for ( { global, local } : SelectorParams ) : string {
18- if ( global . length === 1 && ! local ?. length && global [ 0 ] === ':root' ) {
19- // :root is only applied alone
20- return this . customizer ( ':root' ) ;
19+ if ( global . length === 1 && ! local ?. length && isGlobalSelector ( global [ 0 ] ) ) {
20+ // Global selectors ( :root, body, html) are only applied alone
21+ return this . customizer ( global [ 0 ] ) ;
2122 }
22- const globalWithoutRoot = global . filter ( ( f ) => f !== ':root' ) ;
23+ const customGlobal = global . filter ( ( f ) => ! isGlobalSelector ( f ) ) ;
2324
24- let selector = this . toSelector ( globalWithoutRoot ) ;
25+ let selector = this . toSelector ( customGlobal ) ;
2526 if ( local ?. length ) {
2627 selector += ` ${ this . toSelector ( local ) } ` ;
2728 }
You can’t perform that action at this time.
0 commit comments