-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Input add onEnterPress and onKeyDown props #4250
Conversation
Deploy PR Preview failed. |
src/components/input/index.en.md
Outdated
|
||
In addition, the following native attributes are supported: `maxLength` `minLength` `max` `min` `autoComplete` `enterKeyHint` `pattern` `type` `onFocus` `onBlur` `autoCapitalize` `autoCorrect` | ||
In addition, the following native attributes are supported: `maxLength` `minLength` `max` `min` `autoComplete` `enterKeyHint` `pattern` `type` `onFocus` `onBlur` `autoCapitalize` `autoCorrect` `onKeyDown` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
onKeyUp
要不也一起顺便支持了吧~
@@ -73,6 +75,13 @@ export const Input = forwardRef<InputRef, InputProps>((p, ref) => { | |||
}, | |||
})) | |||
|
|||
const handleKeydown = (e: React.KeyboardEvent<HTMLInputElement>) => { | |||
if (props.onEnterPress && (e.code === 'Enter' || e.keyCode === 13)) { | |||
props.onEnterPress(e) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
本来在想这里的 onEnterPress
事件是不是应该在 onKeyUp
中触发,后来试了一下发现 Google 的逻辑就是 onKeyDown
,也还是挺合理的
src/components/input/index.zh.md
Outdated
@@ -17,8 +17,9 @@ | |||
| clearable | 是否启用清除图标,点击清除图标后会清空输入框 | `boolean` | `false` | | |||
| onClear | 点击清除按钮后触发 | `() => void` | - | | |||
| id | input 元素的 id,常用来配合 label 使用 | `string` | - | | |||
| onEnterPress | 按下回车的回调 | `(e) => void` | - | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里的 e
标一下类型吧~
ok~已补充 |
e4b6a32
to
55a043d
Compare
support #4248