@@ -13,6 +13,7 @@ import { Fade, SlideUp } from './Animation';
1313import { type CarouselType } from '../Carousel' ;
1414import { defaultModalStyles , type ModalStylesConfig } from '../../styles' ;
1515import { isTouch , className } from '../../utils' ;
16+ import componentBaseClassNames from '../componentBaseClassNames' ;
1617
1718type MouseOrKeyboardEvent = MouseEvent | KeyboardEvent ;
1819export type CloseType = ( event : MouseOrKeyboardEvent ) => void ;
@@ -55,6 +56,17 @@ const defaultProps = {
5556 preventScroll : true ,
5657 styles : { } ,
5758} ;
59+
60+ /** Classes that when clicked on, close the backdrop */
61+ const backdropClassNames = new Set (
62+ [
63+ componentBaseClassNames . View ,
64+ componentBaseClassNames . Header ,
65+ componentBaseClassNames . Footer ,
66+ componentBaseClassNames . Track ,
67+ ] . map ( className ) ,
68+ ) ;
69+
5870class Modal extends Component < Props , State > {
5971 commonProps : any ; // TODO
6072 components : ModalComponents ;
@@ -106,10 +118,14 @@ class Modal extends Component<Props, State> {
106118 if ( allowClose ) this . handleClose ( event ) ;
107119 } ;
108120 handleBackdropClick = ( event : MouseEvent ) => {
109- if (
110- ! event . target . classList . contains ( className ( 'view' ) ) ||
111- ! this . props . closeOnBackdropClick
112- ) {
121+ let hasBackdropClassName = false ;
122+ for ( const targetClass of event . target . classList ) {
123+ if ( backdropClassNames . has ( targetClass ) ) {
124+ hasBackdropClassName = true ;
125+ }
126+ }
127+
128+ if ( ! hasBackdropClassName || ! this . props . closeOnBackdropClick ) {
113129 return ;
114130 }
115131
0 commit comments