@@ -10,9 +10,12 @@ import {
1010 type ModalComponents ,
1111} from '../defaultComponents' ;
1212import { Fade , SlideUp } from './Animation' ;
13- import { type CarouselType } from '../Carousel' ;
13+ import { type CarouselType , trackBaseClassName } from '../Carousel' ;
1414import { defaultModalStyles , type ModalStylesConfig } from '../../styles' ;
1515import { isTouch , className } from '../../utils' ;
16+ import { headerBaseClassName } from '../Header' ;
17+ import { footerBaseClassName } from '../Footer' ;
18+ import { viewBaseClassName } from '../View' ;
1619
1720type MouseOrKeyboardEvent = MouseEvent | KeyboardEvent ;
1821export type CloseType = ( event : MouseOrKeyboardEvent ) => void ;
@@ -55,6 +58,17 @@ const defaultProps = {
5558 preventScroll : true ,
5659 styles : { } ,
5760} ;
61+
62+ /** Classes that when clicked on, close the backdrop */
63+ const backdropClassNames = new Set (
64+ [
65+ viewBaseClassName ,
66+ headerBaseClassName ,
67+ footerBaseClassName ,
68+ trackBaseClassName ,
69+ ] . map ( className ) ,
70+ ) ;
71+
5872class Modal extends Component < Props , State > {
5973 commonProps : any ; // TODO
6074 components : ModalComponents ;
@@ -106,10 +120,11 @@ class Modal extends Component<Props, State> {
106120 if ( allowClose ) this . handleClose ( event ) ;
107121 } ;
108122 handleBackdropClick = ( event : MouseEvent ) => {
109- if (
110- ! event . target . classList . contains ( className ( 'view' ) ) ||
111- ! this . props . closeOnBackdropClick
112- ) {
123+ const hasBackdropClassName = event . target . classList . some ( className =>
124+ backdropClassNames . has ( className ) ,
125+ ) ;
126+
127+ if ( ! hasBackdropClassName || ! this . props . closeOnBackdropClick ) {
113128 return ;
114129 }
115130
0 commit comments