import classNames from 'classnames'; import {action} from 'mobx'; import {observer} from 'mobx-react'; import * as React from 'react'; import styles from './FileInputField.scss'; interface FileInputFieldProps { onChange: (newFiles: File[]) => void; multiple?: boolean; className?: string; } @observer export class FileInputField extends React.Component { private fileInput: HTMLInputElement; @action private handleChange = (e: React.ChangeEvent) => { const {files} = e.target; if (files.length > 0) { this.props.onChange(Array.from(files)); this.fileInput.value = null; } } private openFileUploadDialog = () => { this.fileInput.click(); } public render() { const {children, multiple, className} = this.props; return (
{children} this.fileInput = element} className={styles.fileInput}/>
); } }