Skip to content

Commit b524dff

Browse files
authored
fix(Form): support submitting the form automatically when pressing Enter (#3890)
1 parent d2fa38b commit b524dff

File tree

1 file changed

+2
-13
lines changed

1 file changed

+2
-13
lines changed

packages/components/form/Form.tsx

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useRef, useImperativeHandle } from 'react';
1+
import React, { useEffect, useImperativeHandle, useRef } from 'react';
22
import classNames from 'classnames';
33
import useConfig from '../hooks/useConfig';
44
import noop from '../_util/noop';
@@ -38,7 +38,6 @@ const Form = forwardRefWithStatics(
3838
resetType,
3939
rules,
4040
errorMessage = globalFormConfig.errorMessage,
41-
preventSubmitDefault,
4241
disabled,
4342
children,
4443
id,
@@ -61,7 +60,7 @@ const Form = forwardRefWithStatics(
6160
form?.getInternalHooks?.(HOOK_MARK)?.setForm?.(formInstance);
6261

6362
// form 初始化后清空队列
64-
React.useEffect(() => {
63+
useEffect(() => {
6564
form?.getInternalHooks?.(HOOK_MARK)?.flashQueue?.();
6665
}, [form]);
6766

@@ -79,15 +78,6 @@ const Form = forwardRefWithStatics(
7978
onValuesChange(changedValue, allFields);
8079
}
8180

82-
function onKeyDownHandler(e: React.KeyboardEvent<HTMLFormElement>) {
83-
// 禁用 input 输入框回车自动提交 form
84-
if ((e.target as Element).tagName.toLowerCase() !== 'input') return;
85-
if (preventSubmitDefault && e.key === 'Enter') {
86-
e.preventDefault?.();
87-
e.stopPropagation?.();
88-
}
89-
}
90-
9181
return (
9282
<FormContext.Provider
9383
value={{
@@ -118,7 +108,6 @@ const Form = forwardRefWithStatics(
118108
className={formClass}
119109
onSubmit={formInstance.submit}
120110
onReset={onResetHandler}
121-
onKeyDown={onKeyDownHandler}
122111
>
123112
{children}
124113
</form>

0 commit comments

Comments
 (0)