File tree Expand file tree Collapse file tree 1 file changed +31
-0
lines changed
packages/react-dom/src/__tests__ Expand file tree Collapse file tree 1 file changed +31
-0
lines changed Original file line number Diff line number Diff line change @@ -750,6 +750,37 @@ describe('ReactDOMInput', () => {
750750 expect ( handled ) . toBe ( true ) ;
751751 } ) ;
752752
753+ it ( 'should restore uncontrolled inputs to last defaultValue upon reset' , ( ) => {
754+ const inputRef = React . createRef ( ) ;
755+ ReactDOM . render (
756+ < form >
757+ < input defaultValue = "default1" ref = { inputRef } />
758+ < input type = "reset" />
759+ </ form > ,
760+ container ,
761+ ) ;
762+ expect ( inputRef . current . value ) . toBe ( 'default1' ) ;
763+
764+ setUntrackedValue . call ( inputRef . current , 'changed' ) ;
765+ dispatchEventOnNode ( inputRef . current , 'input' ) ;
766+ expect ( inputRef . current . value ) . toBe ( 'changed' ) ;
767+
768+ ReactDOM . render (
769+ < form >
770+ < input defaultValue = "default2" ref = { inputRef } />
771+ < input type = "reset" />
772+ </ form > ,
773+ container ,
774+ ) ;
775+ expect ( inputRef . current . value ) . toBe ( 'changed' ) ;
776+
777+ container . firstChild . reset ( ) ;
778+ // Note: I don't know if we want to always support this.
779+ // But it's current behavior so worth being intentional if we break it.
780+ // https://github.com/facebook/react/issues/4618
781+ expect ( inputRef . current . value ) . toBe ( 'default2' ) ;
782+ } ) ;
783+
753784 it ( 'should not set a value for submit buttons unnecessarily' , ( ) => {
754785 const stub = < input type = "submit" /> ;
755786 ReactDOM . render ( stub , container ) ;
You can’t perform that action at this time.
0 commit comments