Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ClickAwayListener] Add better support for IE11 #4537

Merged
merged 1 commit into from
Jun 29, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"android:setup-port": "adb reverse tcp:8081 tcp:8081"
},
"dependencies": {
"babel-polyfill": "^6.9.1",
"react-title-component": "^1.0.1",
"simple-assign": "^0.1.0"
},
Expand Down
4 changes: 1 addition & 3 deletions docs/webpack-dev-server.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const config = {
entry: [
'webpack/hot/dev-server',
'webpack/hot/only-dev-server',
'./node_modules/babel-polyfill/lib/index.js',
path.resolve(__dirname, 'src/app/app.js'),
],
// Webpack config options on how to obtain modules
Expand Down Expand Up @@ -44,9 +45,6 @@ const config = {
{from: 'src/www/index.html'},
]),
],
externals: {
fs: 'js', // To remove once https://github.com/benjamn/recast/pull/238 is released
},
module: {
// Allow loading of non-es
loaders: [
Expand Down
4 changes: 1 addition & 3 deletions docs/webpack-production.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const CopyWebpackPlugin = require('copy-webpack-plugin');
const config = {
// Entry point to the project
entry: [
'./node_modules/babel-polyfill/lib/index.js',
path.resolve(__dirname, 'src/app/app.js'),
],
// Webpack config options on how to obtain modules
Expand Down Expand Up @@ -56,9 +57,6 @@ const config = {
{from: 'src/www/versions.json'},
]),
],
externals: {
fs: 'fs', // To remove once https://github.com/benjamn/recast/pull/238 is released
},
module: {
// Allow loading of non-es5 js files.
loaders: [
Expand Down
11 changes: 8 additions & 3 deletions src/internal/ClickAwayListener.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export default class ClickAwayListener extends Component {
};

componentDidMount() {
this.isCurrentlyMounted = true;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about using the isMounted name to follow the old method backed in React?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was getting an error by using isMounted. I not remember what it was exactly, but I think it was related to it being a read-only property.
I can get you the error message tomorrow if you'd like

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assignment to read-only properties is not allowed in strict mode in IE11

Uncaught TypeError: Cannot set property isMounted of #<ReactComponent> which has only a getter in Chrome

if (this.props.onClickAway) {
bind(this.handleClickAway);
}
Expand All @@ -36,6 +37,7 @@ export default class ClickAwayListener extends Component {
}

componentWillUnmount() {
this.isCurrentlyMounted = false;
unbind(this.handleClickAway);
}

Expand All @@ -44,10 +46,13 @@ export default class ClickAwayListener extends Component {
return;
}

const el = ReactDOM.findDOMNode(this);
// IE11 support, which trigger the handleClickAway even after the unbind
if (this.isCurrentlyMounted) {
const el = ReactDOM.findDOMNode(this);

if (document.documentElement.contains(event.target) && !isDescendant(el, event.target)) {
this.props.onClickAway(event);
if (document.documentElement.contains(event.target) && !isDescendant(el, event.target)) {
this.props.onClickAway(event);
}
}
};

Expand Down