mirror of
https://github.com/ant-design/ant-design.git
synced 2025-06-11 19:42:54 +08:00
fix: csp not work on icon (#34356)
This commit is contained in:
parent
6ef85f654d
commit
8fe8df777e
@ -16,17 +16,30 @@ describe('ConfigProvider.Icon', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('basic', () => {
|
describe('csp', () => {
|
||||||
const wrapper = mount(
|
it('raw', () => {
|
||||||
<ConfigProvider iconPrefixCls="bamboo" csp={{ nonce: 'light' }}>
|
mount(
|
||||||
<SmileOutlined />
|
<ConfigProvider csp={{ nonce: 'little' }}>
|
||||||
</ConfigProvider>,
|
<SmileOutlined />
|
||||||
);
|
</ConfigProvider>,
|
||||||
|
);
|
||||||
|
|
||||||
const styleNode = document.querySelector('style');
|
const styleNode = document.querySelector('style');
|
||||||
|
expect(styleNode.nonce).toEqual('little');
|
||||||
|
});
|
||||||
|
|
||||||
expect(wrapper.exists('.bamboo-smile')).toBeTruthy();
|
it('mix with iconPrefixCls', () => {
|
||||||
expect(styleNode.nonce).toEqual('light');
|
const wrapper = mount(
|
||||||
|
<ConfigProvider iconPrefixCls="bamboo" csp={{ nonce: 'light' }}>
|
||||||
|
<SmileOutlined />
|
||||||
|
</ConfigProvider>,
|
||||||
|
);
|
||||||
|
|
||||||
|
const styleNode = document.querySelector('style');
|
||||||
|
|
||||||
|
expect(wrapper.exists('.bamboo-smile')).toBeTruthy();
|
||||||
|
expect(styleNode.nonce).toEqual('light');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('nest', () => {
|
it('nest', () => {
|
||||||
|
@ -211,7 +211,7 @@ const ProviderChildren: React.FC<ProviderChildrenProps> = props => {
|
|||||||
|
|
||||||
const memoIconContextValue = React.useMemo(
|
const memoIconContextValue = React.useMemo(
|
||||||
() => ({ prefixCls: iconPrefixCls, csp }),
|
() => ({ prefixCls: iconPrefixCls, csp }),
|
||||||
[iconPrefixCls],
|
[iconPrefixCls, csp],
|
||||||
);
|
);
|
||||||
|
|
||||||
let childNode = children;
|
let childNode = children;
|
||||||
@ -238,7 +238,7 @@ const ProviderChildren: React.FC<ProviderChildrenProps> = props => {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (iconPrefixCls) {
|
if (iconPrefixCls || csp) {
|
||||||
childNode = (
|
childNode = (
|
||||||
<IconContext.Provider value={memoIconContextValue}>{childNode}</IconContext.Provider>
|
<IconContext.Provider value={memoIconContextValue}>{childNode}</IconContext.Provider>
|
||||||
);
|
);
|
||||||
|
Loading…
Reference in New Issue
Block a user