Skip to content

Commit

Permalink
umputun#371 upload image from clipboard
Browse files Browse the repository at this point in the history
  • Loading branch information
Mavrin committed Jul 14, 2019
1 parent 407ce9c commit 063151c
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions frontend/app/components/input/input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ export class Input extends Component<Props, State> {
this.appendError = this.appendError.bind(this);
this.uploadImage = this.uploadImage.bind(this);
this.uploadImages = this.uploadImages.bind(this);
this.onPaste = this.onPaste.bind(this);
}

componentWillReceiveProps(nextProps: Props) {
Expand Down Expand Up @@ -135,6 +136,13 @@ export class Input extends Component<Props, State> {
});
}

onPaste(e: ClipboardEvent) {
if (e.clipboardData && e.clipboardData.files.length > 0) {
const files = (e.clipboardData.files as unknown) as File[];
this.uploadImages(files);
}
}

send(e: Event) {
const text = this.state.text;
const props = this.props;
Expand Down Expand Up @@ -363,6 +371,7 @@ export class Input extends Component<Props, State> {
<div className="input__field-wrapper">
<TextareaAutosize
id={this.textareaId}
onPaste={this.onPaste}
ref={ref => (this.textAreaRef = ref)}
className="input__field"
placeholder="Your comment here"
Expand Down

0 comments on commit 063151c

Please sign in to comment.