Skip to content

Commit

Permalink
feat: add keyCodes.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
mumiao committed Dec 3, 2020
1 parent af80ee3 commit 5b968d1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
3 changes: 3 additions & 0 deletions src/common/keyCodes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const enum KeyCodes {
ENTER = "Enter"
}
20 changes: 10 additions & 10 deletions src/components/input/input.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import './style.scss';
import * as React from 'react';
import { classNames, prefixClaName } from 'mo/common/className';
import { KeyCodes } from 'mo/common/keyCodes'

import TextArea from './TextArea';

Expand All @@ -16,11 +17,11 @@ export interface InputProps {
value?: string;
readonly defaultValue?: string;
readonly className?: string;
readonly onFocus?: (e: React.FocusEvent<HTMLInputElement>) => void;
readonly onBlur?: (e: React.FocusEvent<HTMLInputElement>) => void;
readonly onPressEnter?: React.KeyboardEventHandler<HTMLInputElement>;
readonly onKeyDown?: (e: React.KeyboardEvent<HTMLInputElement>) => void;
readonly onChange?: (e: any) => void;
onFocus?: (e: React.FocusEvent<HTMLInputElement>) => void;
onBlur?: (e: React.FocusEvent<HTMLInputElement>) => void;
onPressEnter?: React.KeyboardEventHandler<HTMLInputElement>;
onKeyDown?: (e: React.KeyboardEvent<HTMLInputElement>) => void;
onChange?: (e: React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement>) => void;
}
export const inputClassName = prefixClaName('input');

Expand Down Expand Up @@ -65,7 +66,6 @@ export interface InputState {
}

class Input extends React.Component<InputProps, InputState> {
// static Search: typeof Search;
static TextArea: typeof TextArea;

static defaultProps = {
Expand Down Expand Up @@ -108,15 +108,15 @@ class Input extends React.Component<InputProps, InputState> {
}

handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
const { onChange } = this.props
this.setValue(e.target.value);
resolveOnChange(this.input, e, this.props.onChange);
resolveOnChange(this.input, e, onChange);
};

handleKeyDown = (e: React.KeyboardEvent<HTMLInputElement>) => {
const { onPressEnter, onKeyDown } = this.props;
// todo
if (e.keyCode === 13 && onPressEnter) {
onPressEnter(e);
if (e.key === KeyCodes.ENTER) {
onPressEnter?.(e);
}
onKeyDown?.(e);
};
Expand Down

0 comments on commit 5b968d1

Please sign in to comment.