Skip to content

Commit e2f8653

Browse files
committed
fix: Fix for async modal roots
1 parent 6ca64cd commit e2f8653

File tree

3 files changed

+8
-4
lines changed

3 files changed

+8
-4
lines changed

pages/modal/async-modal-root.page.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ const getModalRoot: ModalProps['getModalRoot'] = async () => {
1313
};
1414

1515
const removeModalRoot: ModalProps['removeModalRoot'] = root => {
16-
document.body.removeChild(root);
16+
if (root) {
17+
document.body.removeChild(root);
18+
}
1719
};
1820

1921
export default function () {

src/modal/__integ__/modal.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ test(
9898
})
9999
);
100100

101-
(process.env.REACT_VERSION !== '18' ? test : test.skip)(
101+
test(
102102
'renders modal in async root',
103103
useBrowser(async browser => {
104104
const page = new BasePageObject(browser);

src/modal/interfaces.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// SPDX-License-Identifier: Apache-2.0
33
import React from 'react';
44

5+
import { PortalProps } from '@cloudscape-design/component-toolkit/internal';
6+
57
import { FlowType } from '../internal/analytics/interfaces';
68
import { BaseComponentProps } from '../internal/base-component';
79
import { NonCancelableEventHandler } from '../internal/events';
@@ -11,14 +13,14 @@ export interface BaseModalProps {
1113
* Use this property to specify a different dynamic modal root for the dialog.
1214
* The function will be called when a user clicks on the trigger button.
1315
*/
14-
getModalRoot?: () => Promise<HTMLElement>;
16+
getModalRoot?: PortalProps['getContainer'];
1517

1618
/**
1719
* Use this property when `getModalRoot` is used to clean up the modal root
1820
* element after a user closes the dialog. The function receives the return value
1921
* of the most recent getModalRoot call as an argument.
2022
*/
21-
removeModalRoot?: (rootElement: HTMLElement) => void;
23+
removeModalRoot?: PortalProps['removeContainer'];
2224
}
2325

2426
export interface ModalProps extends BaseComponentProps, BaseModalProps {

0 commit comments

Comments
 (0)