File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -66,7 +66,15 @@ const Form = forwardRefWithStatics(
6666 form ?. getInternalHooks ?.( HOOK_MARK ) ?. flashQueue ?.( ) ;
6767 } , [ form ] ) ;
6868
69+ // Dialog / Popup 等通过 Portal 渲染时,DOM 已脱离外层 Form,但 React 合成事件仍沿 Fiber 树冒泡
70+ // 会导致内层 Form 的 reset / submit 误触发外层 Form 的处理逻辑
71+ // 这里过滤掉来自嵌套 Form 的伪冒泡事件
72+ function isEventFromSelf ( e : React . FormEvent < HTMLFormElement > ) {
73+ return e ?. target === formRef . current ;
74+ }
75+
6976 function onResetHandler ( e : React . FormEvent < HTMLFormElement > ) {
77+ if ( ! isEventFromSelf ( e ) ) return ;
7078 [ ...formMapRef . current . values ( ) ] . forEach ( ( formItemRef ) => {
7179 formItemRef ?. current . resetField ( ) ;
7280 } ) ;
@@ -76,6 +84,11 @@ const Form = forwardRefWithStatics(
7684 onReset ?.( { e } ) ;
7785 }
7886
87+ function onSubmitHandler ( e : React . FormEvent < HTMLFormElement > ) {
88+ if ( ! isEventFromSelf ( e ) ) return ;
89+ formInstance . submit ( e ) ;
90+ }
91+
7992 function onFormItemValueChange ( changedValue : Record < string , unknown > ) {
8093 const allFields = formInstance . getFieldsValue ( true ) ;
8194 onValuesChange ( changedValue , allFields ) ;
@@ -110,7 +123,7 @@ const Form = forwardRefWithStatics(
110123 id = { id }
111124 style = { style }
112125 className = { formClass }
113- onSubmit = { formInstance . submit }
126+ onSubmit = { onSubmitHandler }
114127 onReset = { onResetHandler }
115128 >
116129 { children }
Original file line number Diff line number Diff line change 1+ ---
2+ pr_number : 4243
3+ contributor : RylanBot
4+ ---
5+
6+ - fix(Form): 修复 Portal 场景下,内部组件的 ` reset ` 和 ` submit ` 事件冒泡导致外层组件事件被误触发的问题 @RylanBot ([ #4243 ] ( https://github.com/Tencent/tdesign-react/pull/4243 ) )
You can’t perform that action at this time.
0 commit comments