react-spectrum
react-spectrum copied to clipboard
A TextField/ComboBox without label and description loses focus when the errorMessage is shown or hidden.
๐ Bug Report
A TextField component that doesn't have label and description loses focus when the errorMessage is shown or hidden.
๐ค Expected Behavior
The component should not lose focus.
๐ฏ Current Behavior
Focus is lost when the error message is shown or hidden.
๐ Possible Solution
If you don't plan to fix this issue very quickly, maybe you can add a warning in documentation or in the console log.
๐ฆ Context
It is very annoying to lose focus of the input while you are typing . I lost 2 days debugging my application until I found the problem.
This error was first reported 9 months ago, but no bug was logged at that time. I think other people will be affected by this and my suggestion would be to raise the priority of this bug.
๐ป Code Sample
https://codesandbox.io/s/react-spectrum-input-error-problem-6ftlye
๐ Your Environment
| Software | Version(s) |
|---|---|
| react-spectrum | 3.21.1 |
| Browser | Chrome |
| Operating System | macOS Monterey |
๐งข Your Company/Team
Adobe RTCDP Connections
๐ท Tracking Issue (optional)
Possible ways to deal with this as discussed.
- If you're going to provide error messages, provide a description to help people avoid the error in the first place.
- Pass an empty string for the description
We accept PR's as well if we aren't getting to an issue fast enough for you.
The issues is that we have two render paths branched off hasHelpText variable here https://github.com/adobe/react-spectrum/blob/main/packages/%40react-spectrum/label/src/Field.tsx#L52
Wrapping https://github.com/adobe/react-spectrum/blob/main/packages/%40react-spectrum/label/src/Field.tsx#L122 in a React Fragment like line 93 might be enough for React to reuse the elements instead of rendering completely new DOM.
@snowystinger Thanks for your response. I will go on the route of passing an empty string for the description for the time being.
My comment about priority is referring just to the fact that others might go through the same painful debug process like I did. This case doesn't seem very improbable. It was already reported by another person before me.