Skip to content
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

Merged
merged 3 commits into from
Oct 26, 2021

Conversation

jermyn626
Copy link
Contributor

support #4248

@github-actions
Copy link
Contributor

github-actions bot commented Oct 22, 2021

Deploy PR Preview failed.


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`
Copy link
Member

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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

本来在想这里的 onEnterPress 事件是不是应该在 onKeyUp 中触发,后来试了一下发现 Google 的逻辑就是 onKeyDown,也还是挺合理的

@@ -17,8 +17,9 @@
| clearable | 是否启用清除图标,点击清除图标后会清空输入框 | `boolean` | `false` |
| onClear | 点击清除按钮后触发 | `() => void` | - |
| id | input 元素的 id,常用来配合 label 使用 | `string` | - |
| onEnterPress | 按下回车的回调 | `(e) => void` | - |
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里的 e 标一下类型吧~

@jermyn626
Copy link
Contributor Author

jermyn626 commented Oct 25, 2021

ok~已补充

@awmleer awmleer merged commit 7526a65 into ant-design:master Oct 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants