Skip to content

Commit dfeeb21

Browse files
committed
Merge pull request react-bootstrap#204 from react-bootstrap/ios-modal
Fix clicking modal background to close in IOS
2 parents d3974af + 07de801 commit dfeeb21

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

src/Modal.jsx

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/** @jsx React.DOM */
2+
/* global document:false */
23

34
var React = require('react');
45
var classSet = require('./utils/classSet');
@@ -110,9 +111,27 @@ var Modal = React.createClass({
110111
);
111112
},
112113

114+
iosClickHack: function () {
115+
// IOS only allows click events to be delegated to the document on elements
116+
// it considers 'clickable' - anchors, buttons, etc. We fake a click handler on the
117+
// DOM nodes themselves. Remove if handled by React: https://github.com/facebook/react/issues/1169
118+
this.refs.modal.getDOMNode().onclick = function () {};
119+
this.refs.backdrop.getDOMNode().onclick = function () {};
120+
},
121+
113122
componentDidMount: function () {
114123
this._onDocumentKeyupListener =
115124
EventListener.listen(document, 'keyup', this.handleDocumentKeyUp);
125+
126+
if (this.props.backdrop) {
127+
this.iosClickHack();
128+
}
129+
},
130+
131+
componentDidUpdate: function (prevProps) {
132+
if (this.props.backdrop && this.props.backdrop !== prevProps.backdrop) {
133+
this.iosClickHack();
134+
}
116135
},
117136

118137
componentWillUnmount: function () {

0 commit comments

Comments
 (0)