Skip to content

Commit

Permalink
Feat/input legacy method fix (#1090)
Browse files Browse the repository at this point in the history
  • Loading branch information
aso1datov authored Mar 27, 2020
1 parent 44138fc commit 1ecb020
Show file tree
Hide file tree
Showing 10 changed files with 36 additions and 38 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
41 changes: 11 additions & 30 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 25 additions & 8 deletions src/input/input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -248,10 +248,27 @@ export type InputProps = DeepReadonly<{
'data-test-id'?: string;
}>;

type InputState = {
/**
* Состояние фокуса в поле
*/
focused: boolean;

/**
* Ошибка
*/
error: InputProps['error'] | null;

/**
* Содержимое поля ввода
*/
value: string;
}

/**
* Компонент текстового поля ввода.
*/
export class Input extends React.PureComponent<InputProps> {
export class Input extends React.PureComponent<InputProps, InputState> {
protected cn = createCn('input');

static defaultProps: Partial<InputProps> = {
Expand All @@ -262,6 +279,13 @@ export class Input extends React.PureComponent<InputProps> {
resetError: true
};

componentDidUpdate(prevProps: InputProps) {
if (prevProps.error !== this.props.error) {
// eslint-disable-next-line react/no-did-update-set-state
this.setState({ error: this.props.error });
}
}

state = {
focused: false,
error: this.props.error || null,
Expand All @@ -282,13 +306,6 @@ export class Input extends React.PureComponent<InputProps> {
*/
private control;

// eslint-disable-next-line camelcase
UNSAFE_componentWillReceiveProps(nextProps) {
this.setState({
error: nextProps.error
});
}

render() {
const hasAddons = !!this.props.rightAddons || !!this.props.leftAddons;
const hasLeftAddons = !!this.props.leftAddons;
Expand Down

0 comments on commit 1ecb020

Please sign in to comment.