Skip to content
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

[Form] Input focus shift for onClearErrors with multiple Fields #1361

Closed
Eelkedejong opened this issue Jan 28, 2025 · 1 comment · Fixed by #1364
Closed

[Form] Input focus shift for onClearErrors with multiple Fields #1361

Eelkedejong opened this issue Jan 28, 2025 · 1 comment · Fixed by #1364
Labels
bug 🐛 Something doesn't work component: field component: form This is the name of the generic UI component, not the React module!

Comments

@Eelkedejong
Copy link

Bug report

Current behavior

Live example

This is a copy of the Base UI form documentation example, but then with 2 form fields.

Steps:

  1. Create a Form with multiple Fields.
  2. In the onSubmit of the form, set the errors object with an error for both Fields.
  3. Both Fields show the error correctly, the first Field is focussed.
  4. When changing the first input, the error for this field is immediatly cleared (which makes sense, the user is working on fixing the error), except where it goes wrong is that the moment a single change is made, the focus immediatly switches to the second Field that has an error, instead of letter the using fix the input content.

Expected behavior

In step 4, I would expect the focus to remain in the first field. I cannot change more than 1 character before my focus automatically goes to the next field that has an error.

Reproducible example

Codesandbox example: https://codesandbox.io/p/sandbox/busy-sound-9mspmd

Base UI version

For example v1.0.2

Which browser are you using?

Chrome

Which OS are you using?

Mac OS/Windows

@github-actions github-actions bot added the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Jan 28, 2025
@atomiks atomiks added component: form This is the name of the generic UI component, not the React module! component: field bug 🐛 Something doesn't work and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Jan 29, 2025
@atomiks
Copy link
Contributor

atomiks commented Jan 29, 2025

Thanks for reporting @Eelkedejong. onClearErrors gets called immediately onChange of one of the form/field controls, which causes the focus effect to fire whenever the errors prop changes. This should likely be moved to the onSubmit event instead so it runs only once on each submit event

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 Something doesn't work component: field component: form This is the name of the generic UI component, not the React module!
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants