From a75c481ddf880f992fc079326794d32dbc233e7f Mon Sep 17 00:00:00 2001 From: Alina Andrieieva Date: Wed, 18 Sep 2024 18:31:06 +0300 Subject: [PATCH] feat(modal): Ingested changes from rc-dialog to disable modal close button (#50522) Co-authored-by: Alina Andrieieva Co-authored-by: afc163 --- components/_util/hooks/useClosable.tsx | 14 ++++++++------ components/modal/Modal.tsx | 8 ++++++-- components/modal/__tests__/Modal.test.tsx | 5 +++++ components/modal/index.en-US.md | 2 +- components/modal/index.zh-CN.md | 2 +- components/modal/interface.ts | 4 ---- components/modal/style/index.ts | 4 ++++ 7 files changed, 25 insertions(+), 14 deletions(-) diff --git a/components/_util/hooks/useClosable.tsx b/components/_util/hooks/useClosable.tsx index 281eb4dbf8..044a74f8ac 100644 --- a/components/_util/hooks/useClosable.tsx +++ b/components/_util/hooks/useClosable.tsx @@ -1,10 +1,10 @@ import type { ReactNode } from 'react'; import React from 'react'; import CloseOutlined from '@ant-design/icons/CloseOutlined'; +import type { DialogProps } from 'rc-dialog'; import pickAttrs from 'rc-util/lib/pickAttrs'; -export type BaseClosableType = { closeIcon?: React.ReactNode } & React.AriaAttributes; -export type ClosableType = boolean | BaseClosableType; +export type ClosableType = DialogProps['closable']; export type BaseContextClosable = { closable?: ClosableType; closeIcon?: ReactNode }; export type ContextClosable = Partial< @@ -49,7 +49,7 @@ function useClosableConfig(closableCollection?: ClosableCollection | null) { return null; } - let closableConfig: BaseClosableType = { + let closableConfig: ClosableType = { closeIcon: typeof closeIcon !== 'boolean' && closeIcon !== null ? closeIcon : undefined, }; if (closable && typeof closable === 'object') { @@ -104,10 +104,12 @@ export default function useClosable( */ closeIconRender?: (closeIcon: ReactNode) => ReactNode; } = EmptyFallbackCloseCollection, -): [closable: boolean, closeIcon: React.ReactNode | null] { +): [closable: boolean, closeIcon: React.ReactNode, closeBtnIsDisabled: boolean] { // Align the `props`, `context` `fallback` to config object first const propCloseConfig = useClosableConfig(propCloseCollection); const contextCloseConfig = useClosableConfig(contextCloseCollection); + const closeBtnIsDisabled = + typeof propCloseConfig !== 'boolean' ? !!propCloseConfig?.disabled : false; const mergedFallbackCloseCollection = React.useMemo( () => ({ closeIcon: , @@ -149,7 +151,7 @@ export default function useClosable( // Calculate the final closeIcon return React.useMemo(() => { if (mergedClosableConfig === false) { - return [false, null]; + return [false, null, closeBtnIsDisabled]; } const { closeIconRender } = mergedFallbackCloseCollection; @@ -173,6 +175,6 @@ export default function useClosable( } } - return [true, mergedCloseIcon]; + return [true, mergedCloseIcon, closeBtnIsDisabled]; }, [mergedClosableConfig, mergedFallbackCloseCollection]); } diff --git a/components/modal/Modal.tsx b/components/modal/Modal.tsx index d38d76e7df..3533c01568 100644 --- a/components/modal/Modal.tsx +++ b/components/modal/Modal.tsx @@ -107,7 +107,7 @@ const Modal: React.FC = (props) => {