mirror of
https://github.com/ant-design/ant-design.git
synced 2025-01-18 06:03:38 +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', () => {
|
||||
const wrapper = mount(
|
||||
<ConfigProvider iconPrefixCls="bamboo" csp={{ nonce: 'light' }}>
|
||||
<SmileOutlined />
|
||||
</ConfigProvider>,
|
||||
);
|
||||
describe('csp', () => {
|
||||
it('raw', () => {
|
||||
mount(
|
||||
<ConfigProvider csp={{ nonce: 'little' }}>
|
||||
<SmileOutlined />
|
||||
</ConfigProvider>,
|
||||
);
|
||||
|
||||
const styleNode = document.querySelector('style');
|
||||
const styleNode = document.querySelector('style');
|
||||
expect(styleNode.nonce).toEqual('little');
|
||||
});
|
||||
|
||||
expect(wrapper.exists('.bamboo-smile')).toBeTruthy();
|
||||
expect(styleNode.nonce).toEqual('light');
|
||||
it('mix with iconPrefixCls', () => {
|
||||
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', () => {
|
||||
|
@ -211,7 +211,7 @@ const ProviderChildren: React.FC<ProviderChildrenProps> = props => {
|
||||
|
||||
const memoIconContextValue = React.useMemo(
|
||||
() => ({ prefixCls: iconPrefixCls, csp }),
|
||||
[iconPrefixCls],
|
||||
[iconPrefixCls, csp],
|
||||
);
|
||||
|
||||
let childNode = children;
|
||||
@ -238,7 +238,7 @@ const ProviderChildren: React.FC<ProviderChildrenProps> = props => {
|
||||
);
|
||||
}
|
||||
|
||||
if (iconPrefixCls) {
|
||||
if (iconPrefixCls || csp) {
|
||||
childNode = (
|
||||
<IconContext.Provider value={memoIconContextValue}>{childNode}</IconContext.Provider>
|
||||
);
|
||||
|
Loading…
Reference in New Issue
Block a user