@@ -21,8 +21,9 @@ import { ComponentSizeType } from '@Shared/constants'
21
21
import { ConfirmationModalBodyProps , ConfirmationModalProps } from './types'
22
22
import { getPrimaryButtonStyleFromVariant , getConfirmationLabel , getIconFromVariant } from './utils'
23
23
import { Button , ButtonStyleType , ButtonVariantType } from '../Button'
24
- import './confirmationModal.scss'
25
24
import { Backdrop } from '../Backdrop'
25
+ import { useConfirmationModalContext } from './ConfirmationModalContext'
26
+ import './confirmationModal.scss'
26
27
27
28
const ConfirmationModalBody = ( {
28
29
title,
@@ -156,14 +157,40 @@ const ConfirmationModalBody = ({
156
157
)
157
158
}
158
159
159
- const ConfirmationModal = ( { showConfirmationModal, ...props } : ConfirmationModalProps ) => (
160
- < AnimatePresence > { showConfirmationModal ? < ConfirmationModalBody { ...props } /> : null } </ AnimatePresence >
161
- )
160
+ /**
161
+ * NOTE: In some cases, we use a boolean useState to render Modals.
162
+ * This approach can cause issues with the animation of ConfirmationModals,
163
+ * as the animation requires the ConfirmationModal to remain mounted,
164
+ * and only toggle the showConfirmationModal prop to true when it needs to be displayed.
165
+ * This implementation serves as a workaround to allow modals to function as required.
166
+ *
167
+ * Please see NodeActionMenu.tsx as an example of why this is required
168
+ */
169
+ export const BaseConfirmationModal = ( ) => {
170
+ const { props } = useConfirmationModalContext ( )
162
171
163
- const WrapWithShortcutProvider = ( props : ConfirmationModalProps ) => (
164
- < UseRegisterShortcutProvider ignoreTags = { [ 'button' ] } >
165
- < ConfirmationModal { ...props } />
166
- </ UseRegisterShortcutProvider >
167
- )
172
+ return (
173
+ < UseRegisterShortcutProvider ignoreTags = { [ 'button' ] } >
174
+ < AnimatePresence > { props && < ConfirmationModalBody { ...props } /> } </ AnimatePresence >
175
+ </ UseRegisterShortcutProvider >
176
+ )
177
+ }
178
+
179
+ const ConfirmationModal = ( { showConfirmationModal, ...props } : ConfirmationModalProps ) => {
180
+ const { setProps } = useConfirmationModalContext ( )
181
+
182
+ useEffect ( ( ) => {
183
+ setProps ( showConfirmationModal ? props : null )
184
+ } , [ showConfirmationModal ] )
185
+
186
+ useEffect (
187
+ ( ) => ( ) => {
188
+ setProps ( null )
189
+ } ,
190
+ [ ] ,
191
+ )
192
+
193
+ return null
194
+ }
168
195
169
- export default WrapWithShortcutProvider
196
+ export default ConfirmationModal
0 commit comments