File tree Expand file tree Collapse file tree
components/config-provider Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -96,6 +96,33 @@ describe('ConfigProvider.DynamicTheme', () => {
9696 ) . toBeTruthy ( ) ;
9797 } ) ;
9898
99+ it ( 'icon styles should use cssVar key from theme config' , ( ) => {
100+ render (
101+ < ConfigProvider theme = { { cssVar : { key : 'custom-css-var' } } } >
102+ < SmileOutlined />
103+ </ ConfigProvider > ,
104+ ) ;
105+
106+ const dynamicStyles = Array . from ( document . querySelectorAll ( 'style[data-css-hash]' ) ) ;
107+
108+ // Should have styles with the custom cssVar key
109+ expect (
110+ dynamicStyles . some ( ( style ) => {
111+ const { innerHTML } = style ;
112+ return innerHTML . includes ( '.custom-css-var' ) ;
113+ } ) ,
114+ ) . toBeTruthy ( ) ;
115+
116+ // Should NOT have styles with the default css-var-root key
117+ // This ensures icon styles registered inside ConfigProvider use the correct context
118+ expect (
119+ dynamicStyles . some ( ( style ) => {
120+ const { innerHTML } = style ;
121+ return innerHTML . includes ( '.css-var-root' ) ;
122+ } ) ,
123+ ) . toBeFalsy ( ) ;
124+ } ) ;
125+
99126 // eslint-disable-next-line jest/no-disabled-tests
100127 it . skip ( 'layer should affect icon' , ( ) => {
101128 render (
Original file line number Diff line number Diff line change @@ -91,6 +91,18 @@ import type { SizeType } from './SizeContext';
9191import SizeContext , { SizeContextProvider } from './SizeContext' ;
9292import useStyle from './style' ;
9393
94+ /**
95+ * This component registers icon styles inside the DesignTokenContext.Provider
96+ * so that CSS variables use the correct cssVar key from the theme config.
97+ */
98+ const IconStyle : React . FC < { iconPrefixCls : string ; csp ?: CSPConfig } > = ( {
99+ iconPrefixCls,
100+ csp,
101+ } ) => {
102+ useStyle ( iconPrefixCls , csp ) ;
103+ return null ;
104+ } ;
105+
94106export type { Variant } ;
95107
96108export { Variants } ;
@@ -440,8 +452,6 @@ const ProviderChildren: React.FC<ProviderChildrenProps> = (props) => {
440452 const iconPrefixCls = customIconPrefixCls || parentContext . iconPrefixCls || defaultIconPrefixCls ;
441453 const csp = customCsp || parentContext . csp ;
442454
443- useStyle ( iconPrefixCls , csp ) ;
444-
445455 const mergedTheme = useTheme ( theme , parentContext . theme , { prefixCls : getPrefixCls ( '' ) } ) ;
446456
447457 if ( process . env . NODE_ENV !== 'production' ) {
@@ -591,6 +601,7 @@ const ProviderChildren: React.FC<ProviderChildrenProps> = (props) => {
591601
592602 let childNode = (
593603 < >
604+ < IconStyle iconPrefixCls = { iconPrefixCls } csp = { csp } />
594605 < PropWarning dropdownMatchSelectWidth = { dropdownMatchSelectWidth } />
595606 { children }
596607 </ >
You can’t perform that action at this time.
0 commit comments