diff options
author | 2019-02-22 12:32:39 +0100 | |
---|---|---|
committer | 2019-02-22 12:32:39 +0100 | |
commit | 58a5df079320ad99f3c8b369dc163455f8895eec (patch) | |
tree | f40d7ca663d9fe82bc4d8713a1f2559744b458f2 | |
parent | prepare basic workspace edit form (diff) | |
download | ferdium-app-58a5df079320ad99f3c8b369dc163455f8895eec.tar.gz ferdium-app-58a5df079320ad99f3c8b369dc163455f8895eec.tar.zst ferdium-app-58a5df079320ad99f3c8b369dc163455f8895eec.zip |
add on enter key handler for form input component
-rw-r--r-- | packages/forms/src/input/index.tsx | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/packages/forms/src/input/index.tsx b/packages/forms/src/input/index.tsx index de7e7848e..791e0f360 100644 --- a/packages/forms/src/input/index.tsx +++ b/packages/forms/src/input/index.tsx | |||
@@ -25,6 +25,7 @@ interface IProps extends React.InputHTMLAttributes<HTMLInputElement>, IFormField | |||
25 | showPasswordToggle?: boolean; | 25 | showPasswordToggle?: boolean; |
26 | data: IData; | 26 | data: IData; |
27 | inputClassName?: string; | 27 | inputClassName?: string; |
28 | onEnterKey?: Function; | ||
28 | } | 29 | } |
29 | 30 | ||
30 | interface IState { | 31 | interface IState { |
@@ -80,6 +81,13 @@ class InputComponent extends Component<IProps, IState> { | |||
80 | } | 81 | } |
81 | } | 82 | } |
82 | 83 | ||
84 | onInputKeyPress(e: React.KeyboardEvent) { | ||
85 | if (e.key === "Enter") { | ||
86 | const { onEnterKey } = this.props; | ||
87 | onEnterKey && onEnterKey(); | ||
88 | } | ||
89 | } | ||
90 | |||
83 | render() { | 91 | render() { |
84 | const { | 92 | const { |
85 | classes, | 93 | classes, |
@@ -100,6 +108,7 @@ class InputComponent extends Component<IProps, IState> { | |||
100 | placeholder, | 108 | placeholder, |
101 | spellCheck, | 109 | spellCheck, |
102 | onBlur, | 110 | onBlur, |
111 | onEnterKey, | ||
103 | } = this.props; | 112 | } = this.props; |
104 | 113 | ||
105 | const { | 114 | const { |
@@ -144,6 +153,7 @@ class InputComponent extends Component<IProps, IState> { | |||
144 | onChange={this.onChange.bind(this)} | 153 | onChange={this.onChange.bind(this)} |
145 | onBlur={onBlur} | 154 | onBlur={onBlur} |
146 | disabled={disabled} | 155 | disabled={disabled} |
156 | onKeyPress={this.onInputKeyPress.bind(this)} | ||
147 | /> | 157 | /> |
148 | {suffix && ( | 158 | {suffix && ( |
149 | <span className={classes.suffix}> | 159 | <span className={classes.suffix}> |