Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Commit

Permalink
Adds onPaste event to Inputs #3127
Browse files Browse the repository at this point in the history
  • Loading branch information
ngotchac committed Nov 15, 2016
1 parent 039bd3c commit aae7af6
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
1 change: 1 addition & 0 deletions js/src/modals/AddContract/addContract.js
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ export default class AddContract extends Component {
onEditAbi = (abiIn) => {
const { api } = this.context;
const { abi, abiError, abiParsed } = validateAbi(abiIn, api);

this.setState({ abi, abiError, abiParsed });
}

Expand Down
28 changes: 19 additions & 9 deletions js/src/ui/Form/Input/input.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import React, { Component, PropTypes } from 'react';
import { TextField } from 'material-ui';
import { noop } from 'lodash';

import CopyToClipboard from '../../CopyToClipboard';

Expand Down Expand Up @@ -81,7 +82,7 @@ export default class Input extends Component {
}

componentWillReceiveProps (newProps) {
if (newProps.value !== this.props.value) {
if ((newProps.value !== this.props.value) && (newProps.value !== this.state.value)) {
this.setValue(newProps.value);
}
}
Expand Down Expand Up @@ -131,6 +132,7 @@ export default class Input extends Component {
onBlur={ this.onBlur }
onChange={ this.onChange }
onKeyDown={ this.onKeyDown }
onPaste={ this.onPaste }
inputStyle={ inputStyle }
min={ min }
max={ max }
Expand Down Expand Up @@ -180,9 +182,9 @@ export default class Input extends Component {
}

onChange = (event, value) => {
this.setValue(value);

this.props.onChange && this.props.onChange(event, value);
this.setValue(value, () => {
this.props.onChange && this.props.onChange(event, value);
});
}

onBlur = (event) => {
Expand All @@ -196,6 +198,14 @@ export default class Input extends Component {
this.props.onBlur && this.props.onBlur(event);
}

onPaste = (event) => {
const value = event.clipboardData.getData('Text');

window.setTimeout(() => {
this.onSubmit(value);
}, 0);
}

onKeyDown = (event) => {
const { value } = event.target;

Expand All @@ -209,12 +219,12 @@ export default class Input extends Component {
}

onSubmit = (value) => {
this.setValue(value);

this.props.onSubmit && this.props.onSubmit(value);
this.setValue(value, () => {
this.props.onSubmit && this.props.onSubmit(value);
});
}

setValue (value) {
this.setState({ value });
setValue (value, cb = noop) {
this.setState({ value }, cb);
}
}

0 comments on commit aae7af6

Please sign in to comment.