From 19192771072f2b6677a3189864eb50f89a8f322e Mon Sep 17 00:00:00 2001 From: Artem Tarasov Date: Fri, 17 Jul 2020 11:31:23 +0300 Subject: [PATCH] added onInputFile handler --- .../file-input/file-input.stories.js | 3 ++ .../src/components/file-input/index.js | 29 ++++++++++++++----- 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/web/ASC.Web.Components/src/components/file-input/file-input.stories.js b/web/ASC.Web.Components/src/components/file-input/file-input.stories.js index e89fc5af62..11a89b2a72 100644 --- a/web/ASC.Web.Components/src/components/file-input/file-input.stories.js +++ b/web/ASC.Web.Components/src/components/file-input/file-input.stories.js @@ -34,6 +34,9 @@ storiesOf('Components|Input', module) isDisabled={isDisabled} hasError={hasError} hasWarning={hasWarning} + onInput={(e) => { + console.log(e) + }} /> ); diff --git a/web/ASC.Web.Components/src/components/file-input/index.js b/web/ASC.Web.Components/src/components/file-input/index.js index 0e28a7f7e3..8a47507a87 100644 --- a/web/ASC.Web.Components/src/components/file-input/index.js +++ b/web/ASC.Web.Components/src/components/file-input/index.js @@ -83,15 +83,29 @@ class FileInput extends Component { this.inputRef.current.click(); } - onChangeFile = e => this.setState({ - path: e.target.value - }); + onChangeHandler = e => { + this.setState({ + pathName: e.target.value + }) + } - onInputFile = () => this.setState({ - fileName: this.inputRef.current.files[0].name - }); + onInputFile = () => { + const { onInput } = this.props; + + if ( this.inputRef.current.files[0] ) { + this.setState({ + fileName: this.inputRef.current.files[0].name, + data: this.inputRef.current.files[0] + }, () => onInput(this.state.data)); + } else { + this.setState({ + fileName: 'file not choose' + }) + } + } render() { + console.log('render input file') const { fileName } = this.state; const { size, @@ -140,13 +154,14 @@ class FileInput extends Component { hasError={hasError} hasWarning={hasWarning} scale={scale} - onChange={this.onChangeFile} onFocus={this.onIconFileClick} + onChange={this.onChangeHandler} />