From f0d2abdd26f9d959b886bbb86971f5f6a138909a Mon Sep 17 00:00:00 2001 From: sirineJ <112706079+sirineJ@users.noreply.github.com> Date: Fri, 29 Nov 2024 18:29:26 +0100 Subject: [PATCH] make onClose optional --- packages/circuit-ui/components/Dialog/Dialog.tsx | 12 ++++++++---- .../components/Dialog/ModalDialogContext.tsx | 6 ++---- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/packages/circuit-ui/components/Dialog/Dialog.tsx b/packages/circuit-ui/components/Dialog/Dialog.tsx index 6a046dbcda..1653f6780c 100644 --- a/packages/circuit-ui/components/Dialog/Dialog.tsx +++ b/packages/circuit-ui/components/Dialog/Dialog.tsx @@ -44,7 +44,7 @@ import { getFirstFocusableElement } from './DialogService.js'; export interface DialogProps extends Omit, 'children'> { open: boolean; - onClose: () => void; + onClose?: () => void; children: () => ReactNode; closeButtonLabel: string; isModal?: boolean; @@ -60,7 +60,7 @@ export const Dialog = forwardRef( onClose, closeButtonLabel, variant = 'contextual', - isModal = true, + isModal = false, children, className, ...props @@ -130,10 +130,14 @@ export const Dialog = forwardRef( // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore The package is bundled incorrectly dialogPolyfill.registerDialog(dialogElement); - dialogElement.addEventListener('close', onClose); + if (onClose) { + dialogElement.addEventListener('close', onClose); + } return () => { - dialogElement.removeEventListener('close', onClose); + if (onClose) { + dialogElement.removeEventListener('close', onClose); + } }; }, [onClose]); diff --git a/packages/circuit-ui/components/Dialog/ModalDialogContext.tsx b/packages/circuit-ui/components/Dialog/ModalDialogContext.tsx index 9760b3c4b1..1c1db88b0d 100644 --- a/packages/circuit-ui/components/Dialog/ModalDialogContext.tsx +++ b/packages/circuit-ui/components/Dialog/ModalDialogContext.tsx @@ -26,19 +26,17 @@ import { import type { Dialog, DialogProps } from './Dialog.js'; type Optional = Pick, K> & Omit; -export type SetModalArgs = Optional; +export type SetModalArgs = Optional; -// keep initial state compatible prior to the old version of this component +// keep initial state compatible with the old version of this component type ModalDialogState = SetModalArgs & { component: typeof Dialog; id: string | number; }; type ModalDialogContextValue = { - /* eslint-disable @typescript-eslint/no-explicit-any */ setModal: (modal: ModalDialogState) => void; removeModal: (modal: ModalDialogState) => void; - /* eslint-enable @typescript-eslint/no-explicit-any */ }; export interface ModalDialogProviderProps { /**