react icon indicating copy to clipboard operation
react copied to clipboard

In NW.js app, the 'file' type <input> onChange event doesn't fire

Open zhouce opened this issue 10 years ago • 7 comments

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 avatar Jul 18 '16 01:07 zhouce

@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 avatar Jul 18 '16 07:07 stephenkingsley

@stephenkingsley file, not text.

syranide avatar Aug 13 '16 08:08 syranide

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?

jochenberger avatar Sep 23 '16 11:09 jochenberger

Same problem with React 15.3.2 and nw.js environment.

xdroidx avatar Oct 13 '16 08:10 xdroidx

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);
}

Keats avatar Nov 14 '16 02:11 Keats

We’ll need a full example reproducing this to look into it.

gaearon avatar Oct 04 '17 01:10 gaearon

Closing since there was no follow up or reproducing example provided.

aweary avatar Jun 25 '18 18:06 aweary