[Regression] - Hidden form field retains stale value after clearing out a TimeField
- Dominant language
- TypeScript
- Stars
- 15.9k
- Forks
- 1.6k
- Avg merge
- 3d 9m
- Merged PRs (30d)
- 59
Description
### Provide a general summary of the issue here
* Give a TimeField wrapped in a a valid value
* Confirm that [...(new FormData(formNode)).values()] shows the correct value
* Delete the filled out hour or minute fields
* `[...(new FormData(formNode)).values()]` represents the last "good" time, not null
* react-aria-components@1.16.0 did not have this issue
Possibly related to: #9624, #9366
### 🤔 Expected Behavior?
Hidden form field should have an empty string value when the item is invalid
### 😯 Current Behavior
Hidden form field retains the last valid time even though it is stale.
### 💁 Possible Solution
Not sure of the root cause in the implementation, but unit tests should have something along the lines of:
```typescript
const formRef = createRef();
render(
);
...
expect(formRef.current).toHaveFormValues({ 'time-input': '' });
```
This is how I discovered the regression in the first place.
### 🔦 Context
If a team is reliant on default form submission behavior, a user-cleared field won't be recorded properly.
### 🖥️ Steps to Reproduce
https://codesandbox.io/p/sandbox/epic-mestorf-ll25dp?file=%2Fsrc%2FApp.js
```javascript
import React, { useRef, useState, useEffect } from "react";
import { DateInput, DateSegment, TimeField, Form } from "react-aria-components";
import "./styles.css";
export default function App() {
const formRef = useRef(null);
const [value, setValue] = useState(null);
const [formValues, setFormValues] = useState(null);
useEffect(() => {
setFormValues(String([...new FormData(formRef.current).values()]));
}, [value]);
return (
<>
{(segment) => }
Form Value:
{String(formValues)}
);
}
```
* Fill out all fields
* Delete either the hour or minute fields
* Form Value retains its previous value until `{delete}` or `{backspace}` are used to clear all 3 fields, with AM/PM being the final field cleared.
### Version
react-aria-components@1.16.0
### What browsers are you seeing the problem on?
Chrome
### If other, please specify.
_No response_
### What operating system are you using?
Windows
### 🧢 Your Company/Team
athenahealth/Forge
### 🕷 Tracking Issue
_No response_
Contributor guide
Assessment
This issue has not been assessed yet.