@@ -2579,4 +2579,194 @@ describe('ReactDOMForm', () => {
25792579 // Uncontrolled checkbox SHOULD reset
25802580 expect ( checkboxRef . current . checked ) . toBe ( false ) ;
25812581 } ) ;
2582+
2583+ it ( 'controlled select elements should not reset on form submission' , async ( ) => {
2584+ const container = document . createElement ( 'div' ) ;
2585+ const root = ReactDOMClient . createRoot ( container ) ;
2586+
2587+ function App ( ) {
2588+ const [ value , setValue ] = React . useState ( '2' ) ;
2589+ return (
2590+ < form
2591+ action = { ( ) => {
2592+ // Simulate form action
2593+ } } >
2594+ < select value = { value } onChange = { e => setValue ( e . target . value ) } >
2595+ < option value = "1" > Option 1</ option >
2596+ < option value = "2" > Option 2</ option >
2597+ < option value = "3" > Option 3</ option >
2598+ </ select >
2599+ < button type = "submit" > Submit</ button >
2600+ </ form >
2601+ ) ;
2602+ }
2603+
2604+ await act ( ( ) => {
2605+ root . render ( < App /> ) ;
2606+ } ) ;
2607+
2608+ const select = container . querySelector ( 'select' ) ;
2609+ const button = container . querySelector ( 'button' ) ;
2610+
2611+ // Change value to 3
2612+ await act ( ( ) => {
2613+ select . value = '3' ;
2614+ select . dispatchEvent ( new Event ( 'change' , { bubbles : true } ) ) ;
2615+ } ) ;
2616+
2617+ expect ( select . value ) . toBe ( '3' ) ;
2618+
2619+ // Submit form
2620+ await act ( ( ) => {
2621+ button . click ( ) ;
2622+ } ) ;
2623+
2624+ // Controlled select should NOT reset
2625+ expect ( select . value ) . toBe ( '3' ) ;
2626+ } ) ;
2627+ it ( 'controlled select elements should not reset on form submission' , async ( ) => {
2628+ const root = ReactDOMClient . createRoot ( container ) ;
2629+
2630+ function App ( ) {
2631+ const [ value , setValue ] = React . useState ( '2' ) ;
2632+ return (
2633+ < form action = { ( ) => { } } >
2634+ < select value = { value } onChange = { e => setValue ( e . target . value ) } >
2635+ < option value = "1" > Option 1</ option >
2636+ < option value = "2" > Option 2</ option >
2637+ < option value = "3" > Option 3</ option >
2638+ </ select >
2639+ < button type = "submit" > Submit</ button >
2640+ </ form >
2641+ ) ;
2642+ }
2643+
2644+ await act ( ( ) => {
2645+ root . render ( < App /> ) ;
2646+ } ) ;
2647+
2648+ const select = container . querySelector ( 'select' ) ;
2649+ const button = container . querySelector ( 'button' ) ;
2650+
2651+ // Change to option 3
2652+ await act ( ( ) => {
2653+ select . value = '3' ;
2654+ select . dispatchEvent ( new Event ( 'change' , { bubbles : true } ) ) ;
2655+ } ) ;
2656+
2657+ expect ( select . value ) . toBe ( '3' ) ;
2658+
2659+ // Submit form
2660+ await act ( ( ) => {
2661+ button . click ( ) ;
2662+ } ) ;
2663+
2664+ // Controlled select should NOT reset
2665+ expect ( select . value ) . toBe ( '3' ) ;
2666+ } ) ;
2667+
2668+ it ( 'controlled textarea elements should not reset on form submission' , async ( ) => {
2669+ const root = ReactDOMClient . createRoot ( container ) ;
2670+
2671+ function App ( ) {
2672+ const [ text , setText ] = React . useState ( 'initial text' ) ;
2673+ return (
2674+ < form action = { ( ) => { } } >
2675+ < textarea value = { text } onChange = { e => setText ( e . target . value ) } />
2676+ < button type = "submit" > Submit</ button >
2677+ </ form >
2678+ ) ;
2679+ }
2680+
2681+ await act ( ( ) => {
2682+ root . render ( < App /> ) ;
2683+ } ) ;
2684+
2685+ const textarea = container . querySelector ( 'textarea' ) ;
2686+ const button = container . querySelector ( 'button' ) ;
2687+
2688+ // Change value
2689+ await act ( ( ) => {
2690+ textarea . value = 'updated text' ;
2691+ textarea . dispatchEvent ( new Event ( 'input' , { bubbles : true } ) ) ;
2692+ } ) ;
2693+
2694+ expect ( textarea . value ) . toBe ( 'updated text' ) ;
2695+
2696+ // Submit form
2697+ await act ( ( ) => {
2698+ button . click ( ) ;
2699+ } ) ;
2700+
2701+ // Controlled textarea should NOT reset
2702+ expect ( textarea . value ) . toBe ( 'updated text' ) ;
2703+ } ) ;
2704+
2705+ it ( 'uncontrolled select elements should still reset on form submission' , async ( ) => {
2706+ const root = ReactDOMClient . createRoot ( container ) ;
2707+
2708+ function App ( ) {
2709+ return (
2710+ < form action = { ( ) => { } } >
2711+ < select defaultValue = "2" >
2712+ < option value = "1" > Option 1</ option >
2713+ < option value = "2" > Option 2</ option >
2714+ < option value = "3" > Option 3</ option >
2715+ </ select >
2716+ < button type = "submit" > Submit</ button >
2717+ </ form >
2718+ ) ;
2719+ }
2720+
2721+ await act ( ( ) => {
2722+ root . render ( < App /> ) ;
2723+ } ) ;
2724+
2725+ const select = container . querySelector ( 'select' ) ;
2726+ const button = container . querySelector ( 'button' ) ;
2727+
2728+ // Change to option 3
2729+ select . value = '3' ;
2730+ expect ( select . value ) . toBe ( '3' ) ;
2731+
2732+ // Submit form
2733+ await act ( ( ) => {
2734+ button . click ( ) ;
2735+ } ) ;
2736+
2737+ // Uncontrolled select SHOULD reset to defaultValue
2738+ expect ( select . value ) . toBe ( '2' ) ;
2739+ } ) ;
2740+
2741+ it ( 'uncontrolled textarea elements should still reset on form submission' , async ( ) => {
2742+ const root = ReactDOMClient . createRoot ( container ) ;
2743+
2744+ function App ( ) {
2745+ return (
2746+ < form action = { ( ) => { } } >
2747+ < textarea defaultValue = "initial text" />
2748+ < button type = "submit" > Submit</ button >
2749+ </ form >
2750+ ) ;
2751+ }
2752+
2753+ await act ( ( ) => {
2754+ root . render ( < App /> ) ;
2755+ } ) ;
2756+
2757+ const textarea = container . querySelector ( 'textarea' ) ;
2758+ const button = container . querySelector ( 'button' ) ;
2759+
2760+ // Change value
2761+ textarea . value = 'updated text' ;
2762+ expect ( textarea . value ) . toBe ( 'updated text' ) ;
2763+
2764+ // Submit form
2765+ await act ( ( ) => {
2766+ button . click ( ) ;
2767+ } ) ;
2768+
2769+ // Uncontrolled textarea SHOULD reset to defaultValue
2770+ expect ( textarea . value ) . toBe ( 'initial text' ) ;
2771+ } ) ;
25822772} ) ;
0 commit comments