react-spectrum icon indicating copy to clipboard operation
react-spectrum copied to clipboard

A TextField/ComboBox without label and description loses focus when the errorMessage is shown or hidden.

Open dompuiu opened this issue 3 years ago โ€ข 2 comments

๐Ÿ› 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)

dompuiu avatar Sep 01 '22 19:09 dompuiu

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 avatar Sep 01 '22 20:09 snowystinger

@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.

dompuiu avatar Sep 01 '22 20:09 dompuiu