@@ -72,6 +72,27 @@ export function isSelector(key: string): boolean {
7272 ) ;
7373}
7474
75+ /**
76+ * Transform selector affix by converting capitalized words to sub-element selectors.
77+ * Returns a selector prefix with leading and trailing spaces.
78+ *
79+ * Examples:
80+ * '> Body > Row' -> ' > [data-element="Body"] > [data-element="Row"] '
81+ * '> Body > Row >' -> ' > [data-element="Body"] > [data-element="Row"] > '
82+ * '>' -> ' > '
83+ */
84+ function transformSelectorAffix ( affix : string ) : string {
85+ const trimmed = affix . trim ( ) ;
86+ if ( ! trimmed ) return ' ' ;
87+
88+ const tokens = trimmed . split ( / \s + / ) ;
89+ const transformed = tokens . map ( ( token ) =>
90+ / ^ [ A - Z ] / . test ( token ) ? `[data-element="${ token } "]` : token ,
91+ ) ;
92+
93+ return ` ${ transformed . join ( ' ' ) } ` ;
94+ }
95+
7596/**
7697 * Get the selector suffix for a key
7798 */
@@ -85,9 +106,12 @@ function getSelector(key: string, styles?: Styles): string | null {
85106 }
86107
87108 if ( key . match ( / ^ [ A - Z ] / ) ) {
88- // Check if styles object has $: '>' for direct child selector
89- const combinator = styles && ( styles as any ) . $ === '>' ? ' > ' : ' ' ;
90- return `${ combinator } [data-element="${ key } "]` ;
109+ const affix = styles ?. $ ;
110+ if ( affix !== undefined ) {
111+ const prefix = transformSelectorAffix ( String ( affix ) ) ;
112+ return `${ prefix } [data-element="${ key } "]` ;
113+ }
114+ return ` [data-element="${ key } "]` ;
91115 }
92116
93117 return null ;
0 commit comments