Skip to content

Commit 03bbac9

Browse files
committed
fix: Fix for async modal roots
1 parent 58547d1 commit 03bbac9

File tree

3 files changed

+19
-15
lines changed

3 files changed

+19
-15
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/__tests__/snapshot-tests/__snapshots__/documenter.test.ts.snap

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8088,10 +8088,10 @@ You can use any theme provided by Ace.",
80888088
element after a user closes the dialog. The function receives the return value
80898089
of the most recent getModalRoot call as an argument.",
80908090
"inlineType": {
8091-
"name": "(rootElement: HTMLElement) => void",
8091+
"name": "(container: HTMLElement) => void",
80928092
"parameters": [
80938093
{
8094-
"name": "rootElement",
8094+
"name": "container",
80958095
"type": "HTMLElement",
80968096
},
80978097
],
@@ -8100,7 +8100,7 @@ of the most recent getModalRoot call as an argument.",
81008100
},
81018101
"name": "removeModalRoot",
81028102
"optional": true,
8103-
"type": "((rootElement: HTMLElement) => void)",
8103+
"type": "((container: HTMLElement) => void)",
81048104
},
81058105
{
81068106
"description": "List of Ace themes available for selection in preferences dialog. Make sure you include at least one light and at
@@ -8691,10 +8691,10 @@ It contains the following:
86918691
element after a user closes the dialog. The function receives the return value
86928692
of the most recent getModalRoot call as an argument.",
86938693
"inlineType": {
8694-
"name": "(rootElement: HTMLElement) => void",
8694+
"name": "(container: HTMLElement) => void",
86958695
"parameters": [
86968696
{
8697-
"name": "rootElement",
8697+
"name": "container",
86988698
"type": "HTMLElement",
86998699
},
87008700
],
@@ -8703,7 +8703,7 @@ of the most recent getModalRoot call as an argument.",
87038703
},
87048704
"name": "removeModalRoot",
87058705
"optional": true,
8706-
"type": "((rootElement: HTMLElement) => void)",
8706+
"type": "((container: HTMLElement) => void)",
87078707
},
87088708
{
87098709
"description": "Configures the sticky columns preference that can be set for both left and right columns.
@@ -16796,10 +16796,10 @@ render to an element under \`document.body\`.",
1679616796
element after a user closes the dialog. The function receives the return value
1679716797
of the most recent getModalRoot call as an argument.",
1679816798
"inlineType": {
16799-
"name": "(rootElement: HTMLElement) => void",
16799+
"name": "(container: HTMLElement) => void",
1680016800
"parameters": [
1680116801
{
16802-
"name": "rootElement",
16802+
"name": "container",
1680316803
"type": "HTMLElement",
1680416804
},
1680516805
],
@@ -16808,7 +16808,7 @@ of the most recent getModalRoot call as an argument.",
1680816808
},
1680916809
"name": "removeModalRoot",
1681016810
"optional": true,
16811-
"type": "((rootElement: HTMLElement) => void)",
16811+
"type": "((container: HTMLElement) => void)",
1681216812
},
1681316813
{
1681416814
"defaultValue": "'medium'",
@@ -20990,10 +20990,10 @@ and 'Size'.",
2099020990
element after a user closes the dialog. The function receives the return value
2099120991
of the most recent getModalRoot call as an argument.",
2099220992
"inlineType": {
20993-
"name": "(rootElement: HTMLElement) => void",
20993+
"name": "(container: HTMLElement) => void",
2099420994
"parameters": [
2099520995
{
20996-
"name": "rootElement",
20996+
"name": "container",
2099720997
"type": "HTMLElement",
2099820998
},
2099920999
],
@@ -21002,7 +21002,7 @@ of the most recent getModalRoot call as an argument.",
2100221002
},
2100321003
"name": "removeModalRoot",
2100421004
"optional": true,
21005-
"type": "((rootElement: HTMLElement) => void)",
21005+
"type": "((container: HTMLElement) => void)",
2100621006
},
2100721007
{
2100821008
"description": "The current selected resource. Resource has the following properties:

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)