mirror of
https://github.com/ant-design/ant-design.git
synced 2025-06-20 18:11:14 +08:00
fix defaultValue
This commit is contained in:
parent
d61ad7445a
commit
f10cb764e4
@ -2,6 +2,7 @@ import * as React from 'react';
|
|||||||
import * as PropTypes from 'prop-types';
|
import * as PropTypes from 'prop-types';
|
||||||
import classNames from 'classnames';
|
import classNames from 'classnames';
|
||||||
import omit from 'omit.js';
|
import omit from 'omit.js';
|
||||||
|
import { polyfill } from 'react-lifecycles-compat';
|
||||||
import Group from './Group';
|
import Group from './Group';
|
||||||
import Search from './Search';
|
import Search from './Search';
|
||||||
import TextArea from './TextArea';
|
import TextArea from './TextArea';
|
||||||
@ -31,7 +32,7 @@ export interface InputProps
|
|||||||
allowClear?: Boolean;
|
allowClear?: Boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default class Input extends React.Component<InputProps, any> {
|
class Input extends React.Component<InputProps, any> {
|
||||||
static Group: typeof Group;
|
static Group: typeof Group;
|
||||||
static Search: typeof Search;
|
static Search: typeof Search;
|
||||||
static TextArea: typeof TextArea;
|
static TextArea: typeof TextArea;
|
||||||
@ -40,7 +41,6 @@ export default class Input extends React.Component<InputProps, any> {
|
|||||||
static defaultProps = {
|
static defaultProps = {
|
||||||
type: 'text',
|
type: 'text',
|
||||||
disabled: false,
|
disabled: false,
|
||||||
allowClear: false,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static propTypes = {
|
static propTypes = {
|
||||||
@ -65,12 +65,26 @@ export default class Input extends React.Component<InputProps, any> {
|
|||||||
allowClear: PropTypes.bool,
|
allowClear: PropTypes.bool,
|
||||||
};
|
};
|
||||||
|
|
||||||
state = {
|
static getDerivedStateFromProps(nextProps: InputProps, state: any) {
|
||||||
value: '',
|
if ('value' in nextProps) {
|
||||||
|
return {
|
||||||
|
...state,
|
||||||
|
value: nextProps.value,
|
||||||
};
|
};
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
input: HTMLInputElement;
|
input: HTMLInputElement;
|
||||||
|
|
||||||
|
constructor(props: InputProps) {
|
||||||
|
super(props);
|
||||||
|
const value = props.value || props.defaultValue;
|
||||||
|
this.state = {
|
||||||
|
value,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
handleKeyDown = (e: React.KeyboardEvent<HTMLInputElement>) => {
|
handleKeyDown = (e: React.KeyboardEvent<HTMLInputElement>) => {
|
||||||
const { onPressEnter, onKeyDown } = this.props;
|
const { onPressEnter, onKeyDown } = this.props;
|
||||||
if (e.keyCode === 13 && onPressEnter) {
|
if (e.keyCode === 13 && onPressEnter) {
|
||||||
@ -273,3 +287,7 @@ export default class Input extends React.Component<InputProps, any> {
|
|||||||
return <ConfigConsumer>{this.renderComponent}</ConfigConsumer>;
|
return <ConfigConsumer>{this.renderComponent}</ConfigConsumer>;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
polyfill(Input);
|
||||||
|
|
||||||
|
export default Input;
|
||||||
|
Loading…
Reference in New Issue
Block a user