In NW.js app, the 'file' type <input> onChange event doesn't fire
I use react in my node webkit application. I just update the react and react-dom from 0.14.3 to 15.2.0, I haven't changed my code. But the onChange event not fire now, and there is no error console log.
Any help will be appreciated.
@zhouce can I review your code?
just now I created a demo, and the onChange event is no problem.
// index.js
import 'babel-polyfill';
import React, { Component } from 'react';
import { render } from 'react-dom';
class Container extends Component {
constructor() {
super();
this.onChange = this.onChange.bind(this);
this.state = {
text: ''
};
}
onChange(e) {
console.log(e.target.value);
this.setState({
text: e.target.value
});
}
render() {
return (
<div>
hello react
<br />
<input
type="text"
value={this.state.text}
onChange={this.onChange}
/>
</div>
)
}
}
render(
<Container />,
document.getElementById('root')
);
// package.json
"dependencies": {
"babel-polyfill": "^6.9.1",
"react": "^15.2.0",
"react-dom": "^15.2.0"
},
"devDependencies": {
"babel-cli": "^6.7.7",
"babel-core": "^6.3.15",
"babel-loader": "^6.2.0",
"babel-plugin-transform-object-rest-spread": "^6.6.5",
"babel-preset-es2015": "^6.6.0",
"babel-preset-react": "^6.5.0",
"babel-register": "^6.3.13",
"webpack": "^1.13.1",
"webpack-dev-middleware": "^1.6.1"
}
@stephenkingsley file, not text.
I have a similar problem. If I select the same file twice, onChange is only called once in Chrome but twice in Firefox. Given that the file's content may have changed, I feel the latter is correct.
Should I resort to using onInput?
Same problem with React 15.3.2 and nw.js environment.
Same here (React 15.3.2), except it worked on Linux but not on Mac (haven't tried Windows).
Code was:
<input onChange={this.uploadFile.bind(this)} type="file" style={{"display": "none"}} ref="file-upload"/>
Switching to the following works:
componentDidMount() {
this.refs["file-upload"].onchange = this.uploadFile.bind(this);
}
We’ll need a full example reproducing this to look into it.
Closing since there was no follow up or reproducing example provided.