11// 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
33import React , { useCallback , useMemo , useRef , useState } from 'react' ;
44
55import classNames from 'classnames' ;
@@ -18,9 +18,10 @@ import BaseModal from '@restart/ui/Modal';
1818import { getSharedManager } from 'react-bootstrap/BootstrapModalManager' ;
1919import Fade from 'react-bootstrap/Fade' ;
2020import ModalContext from 'react-bootstrap/ModalContext' ;
21- import ModalDialog from 'react-bootstrap/ModalDialog' ;
2221import { useBootstrapPrefix , useIsRTL } from 'react-bootstrap/ThemeProvider' ;
2322
23+ import ModalDialog from './ModalDialog' ;
24+
2425const defaultProps = {
2526 show : false ,
2627 backdrop : true ,
@@ -51,7 +52,10 @@ const Modal = React.forwardRef(
5152 dialogClassName,
5253 contentClassName,
5354 children,
55+ dialogStyle,
56+ contentStyle,
5457 dialogAs : Dialog ,
58+ 'data-bs-theme' : dataBsTheme ,
5559 'aria-labelledby' : ariaLabelledby ,
5660 'aria-describedby' : ariaDescribedby ,
5761 'aria-label' : ariaLabel ,
@@ -139,7 +143,7 @@ const Modal = React.forwardRef(
139143 } ) ;
140144
141145 // 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
146+ // click originates from. If it starts in the modal and then ends outside
143147 // don't close.
144148 const handleDialogMouseDown = ( ) => {
145149 waitingForMouseUpRef . current = true ;
@@ -185,13 +189,16 @@ const Modal = React.forwardRef(
185189 } ;
186190
187191 const handleEscapeKeyDown = e => {
188- if ( ! keyboard && backdrop === 'static' ) {
189- // Call preventDefault to stop modal from closing in restart ui,
190- // then play our animation.
192+ if ( keyboard ) {
193+ onEscapeKeyDown ?. ( e ) ;
194+ } else {
195+ // Call preventDefault to stop modal from closing in @restart /ui.
191196 e . preventDefault ( ) ;
192- handleStaticModalAnimation ( ) ;
193- } else if ( keyboard && onEscapeKeyDown ) {
194- onEscapeKeyDown ( e ) ;
197+
198+ if ( backdrop === 'static' ) {
199+ // Play static modal animation.
200+ handleStaticModalAnimation ( ) ;
201+ }
195202 }
196203 } ;
197204
@@ -224,19 +231,17 @@ const Modal = React.forwardRef(
224231 } ;
225232
226233 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- } ,
234+ backdropProps => (
235+ < div
236+ { ...backdropProps }
237+ className = { classNames (
238+ `${ bsPrefix } -backdrop` ,
239+ backdropClassName ,
240+ ! animation && 'show'
241+ ) }
242+ style = { { zIndex} }
243+ />
244+ ) ,
240245 [ animation , backdropClassName , bsPrefix , zIndex ]
241246 ) ;
242247
@@ -254,21 +259,23 @@ const Modal = React.forwardRef(
254259 className = { classNames (
255260 className ,
256261 bsPrefix ,
257- animateStaticModal && `${ bsPrefix } -static`
262+ animateStaticModal && `${ bsPrefix } -static` ,
263+ ! animation && 'show'
258264 ) }
259265 onClick = { backdrop ? handleClick : undefined }
260266 onMouseUp = { handleMouseUp }
267+ data-bs-theme = { dataBsTheme }
261268 aria-label = { ariaLabel }
262269 aria-labelledby = { ariaLabelledby }
263270 aria-describedby = { ariaDescribedby }
264271 >
265- { /*
266- // @ts -ignore */ }
267272 < Dialog
268273 { ...props }
269274 onMouseDown = { handleDialogMouseDown }
270275 className = { dialogClassName }
271276 contentClassName = { contentClassName }
277+ style = { dialogStyle }
278+ contentStyle = { contentStyle }
272279 >
273280 { children }
274281 </ Dialog >
0 commit comments