Skip to content

Commit 5b968d1

Browse files
committed
feat: add keyCodes.ts
1 parent af80ee3 commit 5b968d1

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

src/common/keyCodes.ts

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export const enum KeyCodes {
2+
ENTER = "Enter"
3+
}

src/components/input/input.tsx

+10-10
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import './style.scss';
22
import * as React from 'react';
33
import { classNames, prefixClaName } from 'mo/common/className';
4+
import { KeyCodes } from 'mo/common/keyCodes'
45

56
import TextArea from './TextArea';
67

@@ -16,11 +17,11 @@ export interface InputProps {
1617
value?: string;
1718
readonly defaultValue?: string;
1819
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;
2425
}
2526
export const inputClassName = prefixClaName('input');
2627

@@ -65,7 +66,6 @@ export interface InputState {
6566
}
6667

6768
class Input extends React.Component<InputProps, InputState> {
68-
// static Search: typeof Search;
6969
static TextArea: typeof TextArea;
7070

7171
static defaultProps = {
@@ -108,15 +108,15 @@ class Input extends React.Component<InputProps, InputState> {
108108
}
109109

110110
handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
111+
const { onChange } = this.props
111112
this.setValue(e.target.value);
112-
resolveOnChange(this.input, e, this.props.onChange);
113+
resolveOnChange(this.input, e, onChange);
113114
};
114115

115116
handleKeyDown = (e: React.KeyboardEvent<HTMLInputElement>) => {
116117
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);
120120
}
121121
onKeyDown?.(e);
122122
};

0 commit comments

Comments
 (0)