Skip to content

Commit 0452c9b

Browse files
committed
Add a regression test for #4618
1 parent c21bab6 commit 0452c9b

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

packages/react-dom/src/__tests__/ReactDOMInput-test.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff 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);

0 commit comments

Comments
 (0)