diff options
Diffstat (limited to 'src/components/ui/Input.tsx')
-rw-r--r-- | src/components/ui/Input.tsx | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/src/components/ui/Input.tsx b/src/components/ui/Input.tsx index 78b3a9200..c22dc5838 100644 --- a/src/components/ui/Input.tsx +++ b/src/components/ui/Input.tsx | |||
@@ -1,8 +1,16 @@ | |||
1 | import { ChangeEvent, Component, createRef, RefObject } from 'react'; | 1 | import { |
2 | ChangeEvent, | ||
3 | ChangeEventHandler, | ||
4 | Component, | ||
5 | createRef, | ||
6 | ReactElement, | ||
7 | RefObject, | ||
8 | } from 'react'; | ||
2 | import { observer } from 'mobx-react'; | 9 | import { observer } from 'mobx-react'; |
3 | import classnames from 'classnames'; | 10 | import classnames from 'classnames'; |
4 | import { defineMessages, injectIntl, WrappedComponentProps } from 'react-intl'; | 11 | import { defineMessages, injectIntl, WrappedComponentProps } from 'react-intl'; |
5 | import { mdiEye, mdiEyeOff } from '@mdi/js'; | 12 | import { mdiEye, mdiEyeOff } from '@mdi/js'; |
13 | import { noop } from 'lodash'; | ||
6 | import { scorePassword as scorePasswordFunc } from '../../helpers/password-helpers'; | 14 | import { scorePassword as scorePasswordFunc } from '../../helpers/password-helpers'; |
7 | import Icon from './icon'; | 15 | import Icon from './icon'; |
8 | import { Field } from '../../@types/mobx-form.types'; | 16 | import { Field } from '../../@types/mobx-form.types'; |
@@ -23,6 +31,8 @@ interface IProps extends WrappedComponentProps { | |||
23 | scorePassword?: boolean; | 31 | scorePassword?: boolean; |
24 | prefix?: string; | 32 | prefix?: string; |
25 | suffix?: string; | 33 | suffix?: string; |
34 | placeholder?: string; | ||
35 | onChange?: ChangeEventHandler<HTMLInputElement>; | ||
26 | } | 36 | } |
27 | 37 | ||
28 | interface IState { | 38 | interface IState { |
@@ -53,14 +63,17 @@ class Input extends Component<IProps, IState> { | |||
53 | } | 63 | } |
54 | 64 | ||
55 | onChange(e: ChangeEvent<HTMLInputElement>): void { | 65 | onChange(e: ChangeEvent<HTMLInputElement>): void { |
56 | const { field, scorePassword } = this.props; | 66 | const { field, scorePassword, onChange = noop } = this.props; |
57 | 67 | ||
58 | if (field.onChange) { | 68 | if (field.onChange) { |
69 | onChange(e); | ||
59 | field.onChange(e); | 70 | field.onChange(e); |
60 | } | 71 | } |
61 | 72 | ||
62 | if (scorePassword) { | 73 | if (scorePassword) { |
63 | this.setState({ passwordScore: scorePasswordFunc(field.value) }); | 74 | this.setState({ |
75 | passwordScore: scorePasswordFunc(field.value as string), | ||
76 | }); | ||
64 | } | 77 | } |
65 | } | 78 | } |
66 | 79 | ||
@@ -70,7 +83,7 @@ class Input extends Component<IProps, IState> { | |||
70 | } | 83 | } |
71 | } | 84 | } |
72 | 85 | ||
73 | render() { | 86 | render(): ReactElement { |
74 | const { | 87 | const { |
75 | field, | 88 | field, |
76 | className = null, | 89 | className = null, |