-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fields without description are losing focus when an error is shown for the first time. #2336
Comments
The possible solution listed in the description was proposed by @snowystinger during a Slack conversation. That won't prevent the field to be rerendered which is not very efficient. On top of that, when the focus need to be restored, the cursor needs to be added at the right position since it is not always at the end of the text from the field. A possible alternative would be to render always the helper text container and have a height of 0 when it is empty. |
Ah, yeah, that cursor issue is annoying. We should have access to it on the ref though through ref.current.selectionStart, but seems like we'd be reinventing the wheel. Might be better to just render the wrapper, however, it does carry some problems when put into a Form. See this issue: |
… is shown for the first time. 🐛 Bug Report If you have a TextField without a description, the focus on the field is lost as soon as an error is shown for the first time. This probably happens for all the fields that have Helper Text option. 🤔 Expected Behavior Field should keep focus. 😯 Current Behavior Field is losing the focus when the error is shown. 💁 Possible Solution Probably use a useLayoutEffect to restore focus to the input if the input had focus previously. 🔦 Context 💻 Code Sample https://codesandbox.io/s/lost-focus-44wtq 🌍 Your Environment Software Version(s) react-spectrum 3.14.0 Browser Chrome Operating System macOS 11.6
… is shown for the first time. 🐛 Bug Report If you have a TextField without a description, the focus on the field is lost as soon as an error is shown for the first time. This probably happens for all the fields that have Helper Text option. 🤔 Expected Behavior Field should keep focus. 😯 Current Behavior Field is losing the focus when the error is shown. 💁 Possible Solution Probably use a useLayoutEffect to restore focus to the input if the input had focus previously. 🔦 Context 💻 Code Sample https://codesandbox.io/s/lost-focus-44wtq 🌍 Your Environment Software Version(s) react-spectrum 3.14.0 Browser Chrome Operating System macOS 11.6
… is shown for the first time. 🐛 Bug Report If you have a TextField without a description, the focus on the field is lost as soon as an error is shown for the first time. This probably happens for all the fields that have Helper Text option. 🤔 Expected Behavior Field should keep focus. 😯 Current Behavior Field is losing the focus when the error is shown. 💁 Possible Solution Probably use a useLayoutEffect to restore focus to the input if the input had focus previously. 🔦 Context 💻 Code Sample https://codesandbox.io/s/lost-focus-44wtq 🌍 Your Environment Software Version(s) react-spectrum 3.14.0 Browser Chrome Operating System macOS 11.6
… is shown for the first time. (#2422)
🐛 Bug Report
If you have a TextField without a description, the focus on the field is lost as soon as an error is shown for the first time. This probably happens for all the fields that have Helper Text option.
🤔 Expected Behavior
Field should keep focus.
😯 Current Behavior
Field is losing the focus when the error is shown.
💁 Possible Solution
Probably use a useLayoutEffect to restore focus to the input if the input had focus previously.
🔦 Context
💻 Code Sample
https://codesandbox.io/s/lost-focus-44wtq
🌍 Your Environment
🧢 Your Company/Team
🕷 Tracking Issue (optional)
The text was updated successfully, but these errors were encountered: