1
1
import './style.scss' ;
2
2
import * as React from 'react' ;
3
3
import { classNames , prefixClaName } from 'mo/common/className' ;
4
+ import { KeyCodes } from 'mo/common/keyCodes'
4
5
5
6
import TextArea from './TextArea' ;
6
7
@@ -16,11 +17,11 @@ export interface InputProps {
16
17
value ?: string ;
17
18
readonly defaultValue ?: string ;
18
19
readonly className ?: string ;
19
- readonly onFocus ?: ( e : React . FocusEvent < HTMLInputElement > ) => void ;
20
- readonly onBlur ?: ( e : React . FocusEvent < HTMLInputElement > ) => void ;
21
- readonly onPressEnter ?: React . KeyboardEventHandler < HTMLInputElement > ;
22
- readonly onKeyDown ?: ( e : React . KeyboardEvent < HTMLInputElement > ) => void ;
23
- readonly onChange ?: ( e : any ) => void ;
20
+ onFocus ?: ( e : React . FocusEvent < HTMLInputElement > ) => void ;
21
+ onBlur ?: ( e : React . FocusEvent < HTMLInputElement > ) => void ;
22
+ onPressEnter ?: React . KeyboardEventHandler < HTMLInputElement > ;
23
+ onKeyDown ?: ( e : React . KeyboardEvent < HTMLInputElement > ) => void ;
24
+ onChange ?: ( e : React . ChangeEvent < HTMLInputElement | HTMLTextAreaElement > ) => void ;
24
25
}
25
26
export const inputClassName = prefixClaName ( 'input' ) ;
26
27
@@ -65,7 +66,6 @@ export interface InputState {
65
66
}
66
67
67
68
class Input extends React . Component < InputProps , InputState > {
68
- // static Search: typeof Search;
69
69
static TextArea : typeof TextArea ;
70
70
71
71
static defaultProps = {
@@ -108,15 +108,15 @@ class Input extends React.Component<InputProps, InputState> {
108
108
}
109
109
110
110
handleChange = ( e : React . ChangeEvent < HTMLInputElement > ) => {
111
+ const { onChange } = this . props
111
112
this . setValue ( e . target . value ) ;
112
- resolveOnChange ( this . input , e , this . props . onChange ) ;
113
+ resolveOnChange ( this . input , e , onChange ) ;
113
114
} ;
114
115
115
116
handleKeyDown = ( e : React . KeyboardEvent < HTMLInputElement > ) => {
116
117
const { onPressEnter, onKeyDown } = this . props ;
117
- // todo
118
- if ( e . keyCode === 13 && onPressEnter ) {
119
- onPressEnter ( e ) ;
118
+ if ( e . key === KeyCodes . ENTER ) {
119
+ onPressEnter ?.( e ) ;
120
120
}
121
121
onKeyDown ?.( e ) ;
122
122
} ;
0 commit comments