1
1
// vendored from React-Bootstrap to allow us to set z-index of Modal backdrop
2
- // https://github.com/react-bootstrap/react-bootstrap/blob/93a8a0ef29409293dd69fad5873ad791634b3ed1 /src/Modal.tsx
2
+ // https://github.com/react-bootstrap/react-bootstrap/blob/be23c304fa40ddb209919b0faac1e5dd8cef53ad /src/Modal.tsx
3
3
import React , { useCallback , useMemo , useRef , useState } from 'react' ;
4
4
5
5
import classNames from 'classnames' ;
@@ -52,6 +52,7 @@ const Modal = React.forwardRef(
52
52
contentClassName,
53
53
children,
54
54
dialogAs : Dialog ,
55
+ 'data-bs-theme' : dataBsTheme ,
55
56
'aria-labelledby' : ariaLabelledby ,
56
57
'aria-describedby' : ariaDescribedby ,
57
58
'aria-label' : ariaLabel ,
@@ -139,7 +140,7 @@ const Modal = React.forwardRef(
139
140
} ) ;
140
141
141
142
// We prevent the modal from closing during a drag by detecting where the
142
- // the click originates from. If it starts in the modal and then ends outside
143
+ // click originates from. If it starts in the modal and then ends outside
143
144
// don't close.
144
145
const handleDialogMouseDown = ( ) => {
145
146
waitingForMouseUpRef . current = true ;
@@ -185,13 +186,16 @@ const Modal = React.forwardRef(
185
186
} ;
186
187
187
188
const handleEscapeKeyDown = e => {
188
- if ( ! keyboard && backdrop === 'static' ) {
189
- // Call preventDefault to stop modal from closing in restart ui,
190
- // then play our animation.
189
+ if ( keyboard ) {
190
+ onEscapeKeyDown ?. ( e ) ;
191
+ } else {
192
+ // Call preventDefault to stop modal from closing in @restart /ui.
191
193
e . preventDefault ( ) ;
192
- handleStaticModalAnimation ( ) ;
193
- } else if ( keyboard && onEscapeKeyDown ) {
194
- onEscapeKeyDown ( e ) ;
194
+
195
+ if ( backdrop === 'static' ) {
196
+ // Play static modal animation.
197
+ handleStaticModalAnimation ( ) ;
198
+ }
195
199
}
196
200
} ;
197
201
@@ -224,19 +228,17 @@ const Modal = React.forwardRef(
224
228
} ;
225
229
226
230
const renderBackdrop = useCallback (
227
- backdropProps => {
228
- return (
229
- < div
230
- { ...backdropProps }
231
- className = { classNames (
232
- `${ bsPrefix } -backdrop` ,
233
- backdropClassName ,
234
- ! animation && 'show'
235
- ) }
236
- style = { { zIndex} }
237
- />
238
- ) ;
239
- } ,
231
+ backdropProps => (
232
+ < div
233
+ { ...backdropProps }
234
+ className = { classNames (
235
+ `${ bsPrefix } -backdrop` ,
236
+ backdropClassName ,
237
+ ! animation && 'show'
238
+ ) }
239
+ style = { { zIndex} }
240
+ />
241
+ ) ,
240
242
[ animation , backdropClassName , bsPrefix , zIndex ]
241
243
) ;
242
244
@@ -254,16 +256,16 @@ const Modal = React.forwardRef(
254
256
className = { classNames (
255
257
className ,
256
258
bsPrefix ,
257
- animateStaticModal && `${ bsPrefix } -static`
259
+ animateStaticModal && `${ bsPrefix } -static` ,
260
+ ! animation && 'show'
258
261
) }
259
262
onClick = { backdrop ? handleClick : undefined }
260
263
onMouseUp = { handleMouseUp }
264
+ data-bs-theme = { dataBsTheme }
261
265
aria-label = { ariaLabel }
262
266
aria-labelledby = { ariaLabelledby }
263
267
aria-describedby = { ariaDescribedby }
264
268
>
265
- { /*
266
- // @ts -ignore */ }
267
269
< Dialog
268
270
{ ...props }
269
271
onMouseDown = { handleDialogMouseDown }
0 commit comments