Skip to content

Commit 0a93ed9

Browse files
Backdrop and ESC to Close
1 parent a43d477 commit 0a93ed9

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

react-lightbox.jsx

+10-1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,15 @@ var LightboxModal = React.createClass({
4545
padding: '11px 3px',
4646
textDecoration: 'none'
4747
},
48+
49+
componentDidMount: function(){
50+
document.addEventListener("keydown", function (e) {
51+
if ( (this.props.display) && (e.keyCode === 27) ){
52+
this.props.closeLightbox();
53+
}
54+
}.bind(this));
55+
},
56+
4857
render: function(){
4958

5059
for (j in this.props){
@@ -56,7 +65,7 @@ var LightboxModal = React.createClass({
5665
if (this.props.display){
5766
return (
5867
<div>
59-
<div style={this.blackOverlayStyles} />
68+
<div style={this.blackOverlayStyles} onClick={this.props.closeLightbox} />
6069
<div style={this.whiteContentStyles}>
6170
<a style={this.closeTagStyles} onClick={this.props.closeLightbox}>&times;</a>
6271
{this.props.children}

0 commit comments

Comments
 (0)