@@ -123,6 +123,9 @@ const ReactImageLightbox = React.createClass({
123123
124124 // Padding (px) between the edge of the window and the lightbox
125125 imagePadding : PropTypes . number ,
126+
127+ // When true, clicks outside of the image close the lightbox
128+ clickOutsideToClose : PropTypes . bool ,
126129 } ,
127130
128131 getDefaultProps ( ) {
@@ -140,6 +143,7 @@ const ReactImageLightbox = React.createClass({
140143 keyRepeatKeyupBonus : 40 ,
141144
142145 imagePadding : 10 ,
146+ clickOutsideToClose : true ,
143147 } ;
144148 } ,
145149
@@ -531,12 +535,12 @@ const ReactImageLightbox = React.createClass({
531535
532536 // Request that the lightbox be closed
533537 requestClose ( event ) {
534- const closeLightbox = ( ) => {
535- // Call the parent close request
536- return this . props . onCloseRequest ( event ) ;
537- } ;
538+ // Call the parent close request
539+ const closeLightbox = ( ) => this . props . onCloseRequest ( event ) ;
538540
539- if ( this . props . animationDisabled || ( event . type === 'keydown' && ! this . props . animationOnKeyInput ) ) {
541+ if ( this . props . animationDisabled ||
542+ ( event . type === 'keydown' && ! this . props . animationOnKeyInput )
543+ ) {
540544 // No animation
541545 return closeLightbox ( ) ;
542546 } else {
@@ -591,6 +595,12 @@ const ReactImageLightbox = React.createClass({
591595 this . requestMove ( 'next' , event ) ;
592596 } ,
593597
598+ closeIfClickInner ( event ) {
599+ if ( event . target . className . search ( / \b i n n e r \b / ) > - 1 ) {
600+ this . requestClose ( event ) ;
601+ }
602+ } ,
603+
594604 // Attach key and mouse input events
595605 attachListeners ( ) {
596606 if ( ! this . listenersAttached ) {
@@ -954,6 +964,7 @@ const ReactImageLightbox = React.createClass({
954964
955965 < div // Image holder
956966 className = "inner"
967+ onClick = { this . props . clickOutsideToClose ? this . closeIfClickInner : noop }
957968 style = { [ Styles . inner ] }
958969 >
959970 { images }
0 commit comments