From be058e4794400eba55c935bf4bac6461e729fa46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BA=8C=E8=B4=A7=E7=88=B1=E5=90=83=E7=99=BD=E8=90=9D?= =?UTF-8?q?=E5=8D=9C?= Date: Wed, 17 Jan 2024 17:40:04 +0800 Subject: [PATCH] fix: Modal static func (#47010) * fix: Modal static func * chore: clean up * chore: clean up --- components/config-provider/index.tsx | 6 ++++++ components/modal/__tests__/confirm.test.tsx | 2 +- components/modal/confirm.tsx | 4 ++-- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/components/config-provider/index.tsx b/components/config-provider/index.tsx index 3eec6dc441..afaebc27bf 100644 --- a/components/config-provider/index.tsx +++ b/components/config-provider/index.tsx @@ -266,6 +266,12 @@ const setGlobalConfig = (props: GlobalConfigProps) => { }; export const globalConfig = () => ({ + getPrefixCls: (suffixCls?: string, customizePrefixCls?: string) => { + if (customizePrefixCls) { + return customizePrefixCls; + } + return suffixCls ? `${getGlobalPrefixCls()}-${suffixCls}` : getGlobalPrefixCls(); + }, getIconPrefixCls: getGlobalIconPrefixCls, getRootPrefixCls: () => { // If Global prefixCls provided, use this diff --git a/components/modal/__tests__/confirm.test.tsx b/components/modal/__tests__/confirm.test.tsx index e9de77584c..29f3547ee0 100644 --- a/components/modal/__tests__/confirm.test.tsx +++ b/components/modal/__tests__/confirm.test.tsx @@ -468,7 +468,7 @@ describe('Modal.confirm triggers callbacks correctly', () => { expect($$('.custom-modal-wrap')).toHaveLength(1); expect($$('.custom-modal-confirm')).toHaveLength(1); expect($$('.custom-modal-confirm-body-wrapper')).toHaveLength(1); - expect($$('.custom-modal-btn')).toHaveLength(2); + expect($$('.ant-btn')).toHaveLength(2); }); it('should be Modal.confirm without mask', async () => { diff --git a/components/modal/confirm.tsx b/components/modal/confirm.tsx index 3c3e26c3b7..671a284977 100644 --- a/components/modal/confirm.tsx +++ b/components/modal/confirm.tsx @@ -29,7 +29,7 @@ const ConfirmDialogWrapper: React.FC = (props) => { const runtimeLocale = getConfirmLocale(); const config = useContext(ConfigContext); - const rootPrefixCls = customizePrefixCls || getRootPrefixCls() || config.getPrefixCls(); + const rootPrefixCls = getRootPrefixCls() || config.getPrefixCls(); // because Modal.config set rootPrefixCls, which is different from other components const prefixCls = customizePrefixCls || `${rootPrefixCls}-modal`; @@ -98,7 +98,7 @@ export default function confirm(config: ModalFuncProps) { * Sync render blocks React event. Let's make this async. */ timeoutId = setTimeout(() => { - const rootPrefixCls = global.getRootPrefixCls(); + const rootPrefixCls = global.getPrefixCls(undefined, getRootPrefixCls()); const iconPrefixCls = global.getIconPrefixCls(); const theme = global.getTheme();