diff --git a/src/components/Dialog/context.ts b/src/components/Dialog/context.ts index 1caa4eac85..b7e3c78d5e 100644 --- a/src/components/Dialog/context.ts +++ b/src/components/Dialog/context.ts @@ -13,6 +13,7 @@ import { type DialogControlRefProps, type DialogOuterProps, } from '#/components/Dialog/types' +import {IS_DEV} from '#/env' import {BottomSheetSnapPoint} from '../../../modules/bottom-sheet/src/BottomSheet.types' export const Context = createContext({ @@ -50,10 +51,28 @@ export function useDialogControl(): DialogOuterProps['control'] { id, ref: control, open: () => { - control.current.open() + if (control.current) { + control.current.open() + } else { + if (IS_DEV) { + console.warn( + 'Attemped to open a dialog control that was not attached to a dialog!\n' + + 'Please ensure that the Dialog is mounted when calling open/close', + ) + } + } }, close: cb => { - control.current.close(cb) + if (control.current) { + control.current.close(cb) + } else { + if (IS_DEV) { + console.warn( + 'Attemped to close a dialog control that was not attached to a dialog!\n' + + 'Please ensure that the Dialog is mounted when calling open/close', + ) + } + } }, }), [id, control],