diff --git a/.changeset/thin-ladybugs-travel.md b/.changeset/thin-ladybugs-travel.md new file mode 100644 index 00000000000..93489b128ce --- /dev/null +++ b/.changeset/thin-ladybugs-travel.md @@ -0,0 +1,5 @@ +--- +'@primer/react': patch +--- + +Ensure ConfirmationDialog adds host element to the DOM diff --git a/src/ConfirmationDialog/ConfirmationDialog.tsx b/src/ConfirmationDialog/ConfirmationDialog.tsx index d659ab23e1c..0fa9a28dd49 100644 --- a/src/ConfirmationDialog/ConfirmationDialog.tsx +++ b/src/ConfirmationDialog/ConfirmationDialog.tsx @@ -16,7 +16,7 @@ export interface ConfirmationDialogProps { * Required. This callback is invoked when a gesture to close the dialog * is performed. The first argument indicates the gesture. */ - onClose: (gesture: 'confirm' | 'cancel' | 'close-button' | 'cancel' | 'escape') => void + onClose: (gesture: 'confirm' | 'close-button' | 'cancel' | 'escape') => void /** * Required. The title of the ConfirmationDialog. This is usually a brief @@ -145,11 +145,14 @@ export const ConfirmationDialog: React.FC & {content: React.ReactNode} async function confirm(themeProps: ThemeProviderProps, options: ConfirmOptions): Promise { const {content, ...confirmationDialogProps} = options return new Promise(resolve => { - const root = createRoot(document.createElement('div')) + hostElement = document.createElement('div') + if (!hostElement.isConnected) document.body.append(hostElement) + const root = createRoot(hostElement) const onClose: ConfirmationDialogProps['onClose'] = gesture => { root.unmount() if (gesture === 'confirm') {