Merge pull request #3456 from ethcore/ng-paste-input-submit

Adds onPaste event to Inputs
This commit is contained in:
Gav Wood 2016-11-16 11:18:29 +08:00 committed by GitHub
commit 06112255ae
2 changed files with 20 additions and 9 deletions

View File

@ -227,6 +227,7 @@ export default class AddContract extends Component {
onEditAbi = (abiIn) => { onEditAbi = (abiIn) => {
const { api } = this.context; const { api } = this.context;
const { abi, abiError, abiParsed } = validateAbi(abiIn, api); const { abi, abiError, abiParsed } = validateAbi(abiIn, api);
this.setState({ abi, abiError, abiParsed }); this.setState({ abi, abiError, abiParsed });
} }

View File

@ -16,6 +16,7 @@
import React, { Component, PropTypes } from 'react'; import React, { Component, PropTypes } from 'react';
import { TextField } from 'material-ui'; import { TextField } from 'material-ui';
import { noop } from 'lodash';
import CopyToClipboard from '../../CopyToClipboard'; import CopyToClipboard from '../../CopyToClipboard';
@ -81,7 +82,7 @@ export default class Input extends Component {
} }
componentWillReceiveProps (newProps) { componentWillReceiveProps (newProps) {
if (newProps.value !== this.props.value) { if ((newProps.value !== this.props.value) && (newProps.value !== this.state.value)) {
this.setValue(newProps.value); this.setValue(newProps.value);
} }
} }
@ -131,6 +132,7 @@ export default class Input extends Component {
onBlur={ this.onBlur } onBlur={ this.onBlur }
onChange={ this.onChange } onChange={ this.onChange }
onKeyDown={ this.onKeyDown } onKeyDown={ this.onKeyDown }
onPaste={ this.onPaste }
inputStyle={ inputStyle } inputStyle={ inputStyle }
min={ min } min={ min }
max={ max } max={ max }
@ -180,9 +182,9 @@ export default class Input extends Component {
} }
onChange = (event, value) => { onChange = (event, value) => {
this.setValue(value); this.setValue(value, () => {
this.props.onChange && this.props.onChange(event, value);
this.props.onChange && this.props.onChange(event, value); });
} }
onBlur = (event) => { onBlur = (event) => {
@ -196,6 +198,14 @@ export default class Input extends Component {
this.props.onBlur && this.props.onBlur(event); this.props.onBlur && this.props.onBlur(event);
} }
onPaste = (event) => {
const value = event.clipboardData.getData('Text');
window.setTimeout(() => {
this.onSubmit(value);
}, 0);
}
onKeyDown = (event) => { onKeyDown = (event) => {
const { value } = event.target; const { value } = event.target;
@ -209,12 +219,12 @@ export default class Input extends Component {
} }
onSubmit = (value) => { onSubmit = (value) => {
this.setValue(value); this.setValue(value, () => {
this.props.onSubmit && this.props.onSubmit(value);
this.props.onSubmit && this.props.onSubmit(value); });
} }
setValue (value) { setValue (value, cb = noop) {
this.setState({ value }); this.setState({ value }, cb);
} }
} }