Skip to content

Commit

Permalink
fix ImagePicker for compat preact fix #1486 (#1487)
Browse files Browse the repository at this point in the history
* fix #1486 modify the implementation of image-picker ref

* fix: remove unuse operator
  • Loading branch information
pingan1927 authored and paranoidjk committed Jul 13, 2017
1 parent 869bdf2 commit 8bf5271
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions components/image-picker/index.web.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ export default class ImagePicker extends React.Component<ImagePickerPropTypes, a
selectable: true,
};

fileSelectorInput: any;

// http://stackoverflow.com/questions/7584794/accessing-jpeg-exif-rotation-data-in-javascript-on-the-client-side
getOrientation = (file, callback) => {
const reader = new FileReader();
Expand Down Expand Up @@ -103,8 +105,8 @@ export default class ImagePicker extends React.Component<ImagePickerPropTypes, a
}

onFileChange = () => {
const fileSelectorEl = (this.refs as any).fileSelectorInput;
if (fileSelectorEl.files && fileSelectorEl.files.length) {
const fileSelectorEl = this.fileSelectorInput;
if (fileSelectorEl && fileSelectorEl.files && fileSelectorEl.files.length) {
const file = fileSelectorEl.files[0];
const reader = new FileReader();
reader.onload = (e) => {
Expand Down Expand Up @@ -179,7 +181,7 @@ export default class ImagePicker extends React.Component<ImagePickerPropTypes, a
aria-label="Choose and add image"
>
<input
ref="fileSelectorInput"
ref={(input) => { this.fileSelectorInput = input; }}
type="file"
accept="image/jpg,image/jpeg,image/png,image/gif"
onChange={() => { this.onFileChange(); }}
Expand Down

0 comments on commit 8bf5271

Please sign in to comment.