improve code style

This commit is contained in:
afc163 2016-06-10 15:29:01 +08:00
parent 8877fe599a
commit 82a55adfc7

View File

@ -1,4 +1,4 @@
import React from 'react';
import React, { Component, PropTypes } from 'react';
import classNames from 'classnames';
function fixControlledValue(value) {
@ -8,7 +8,7 @@ function fixControlledValue(value) {
return value;
}
export default class Input extends React.Component {
export default class Input extends Component {
static defaultProps = {
defaultValue: '',
disabled: false,
@ -19,21 +19,21 @@ export default class Input extends React.Component {
}
static propTypes = {
type: React.PropTypes.string,
id: React.PropTypes.oneOfType([
React.PropTypes.string,
React.PropTypes.number,
type: PropTypes.string,
id: PropTypes.oneOfType([
PropTypes.string,
PropTypes.number,
]),
size: React.PropTypes.oneOf(['small', 'default', 'large']),
disabled: React.PropTypes.bool,
value: React.PropTypes.any,
defaultValue: React.PropTypes.any,
className: React.PropTypes.string,
addonBefore: React.PropTypes.node,
addonAfter: React.PropTypes.node,
prefixCls: React.PropTypes.string,
onPressEnter: React.PropTypes.func,
onKeyDown: React.PropTypes.func,
size: PropTypes.oneOf(['small', 'default', 'large']),
disabled: PropTypes.bool,
value: PropTypes.any,
defaultValue: PropTypes.any,
className: PropTypes.string,
addonBefore: PropTypes.node,
addonAfter: PropTypes.node,
prefixCls: PropTypes.string,
onPressEnter: PropTypes.func,
onKeyDown: PropTypes.func,
}
handleKeyDown = (e) => {
@ -87,7 +87,6 @@ export default class Input extends React.Component {
[props.className]: !!props.className,
});
let placeholder = props.placeholder;
if ('value' in props) {
props.value = fixControlledValue(props.value);
// Input elements must be either controlled or uncontrolled,
@ -98,14 +97,20 @@ export default class Input extends React.Component {
switch (props.type) {
case 'textarea':
return (
<textarea {...props} placeholder={placeholder}
className={inputClassName} onKeyDown={this.handleKeyDown} ref="input"
<textarea
{...props}
className={inputClassName}
onKeyDown={this.handleKeyDown}
ref="input"
/>
);
default:
return (
<input {...props} placeholder={placeholder}
className={inputClassName} onKeyDown={this.handleKeyDown} ref="input"
<input
{...props}
className={inputClassName}
onKeyDown={this.handleKeyDown}
ref="input"
/>
);
}