@@ -481,6 +481,7 @@ describe('ReactDOMForm', () => {
481481 it ( 'can read the clicked button in the formdata event' , async ( ) => {
482482 const inputRef = React . createRef ( ) ;
483483 const buttonRef = React . createRef ( ) ;
484+ const outsideButtonRef = React . createRef ( ) ;
484485 let button ;
485486 let title ;
486487
@@ -492,14 +493,27 @@ describe('ReactDOMForm', () => {
492493 const root = ReactDOMClient . createRoot ( container ) ;
493494 await act ( async ( ) => {
494495 root . render (
495- < form action = { action } >
496- < input type = "text" name = "title" defaultValue = "hello" />
497- < input type = "submit" name = "button" value = "save" />
498- < input type = "submit" name = "button" value = "delete" ref = { inputRef } />
499- < button name = "button" value = "edit" ref = { buttonRef } >
500- Edit
496+ < >
497+ < form action = { action } >
498+ < input type = "text" name = "title" defaultValue = "hello" />
499+ < input type = "submit" name = "button" value = "save" />
500+ < input type = "submit" name = "button" value = "delete" ref = { inputRef } />
501+ < button name = "button" value = "edit" ref = { buttonRef } >
502+ Edit
503+ </ button >
504+ </ form >
505+ < form id = "form" action = { action } >
506+ < input type = "text" name = "title" defaultValue = "hello" />
507+ </ form >
508+ < button
509+ form = "form"
510+ name = "button"
511+ value = "outside"
512+ ref = { outsideButtonRef } >
513+ Button outside form
501514 </ button >
502- </ form > ,
515+ ,
516+ </ > ,
503517 ) ;
504518 } ) ;
505519
@@ -520,6 +534,11 @@ describe('ReactDOMForm', () => {
520534 expect ( button ) . toBe ( 'edit' ) ;
521535 expect ( title ) . toBe ( 'hello' ) ;
522536
537+ await submit ( outsideButtonRef . current ) ;
538+
539+ expect ( button ) . toBe ( 'outside' ) ;
540+ expect ( title ) . toBe ( 'hello' ) ;
541+
523542 // Ensure that the type field got correctly restored
524543 expect ( inputRef . current . getAttribute ( 'type' ) ) . toBe ( 'submit' ) ;
525544 expect ( buttonRef . current . getAttribute ( 'type' ) ) . toBe ( null ) ;
0 commit comments