Feature suggestion: Focus on first errored field #715
-
This would improve the accessibility of the form |
Beta Was this translation helpful? Give feedback.
Replies: 7 comments 14 replies
-
+1 it's also useful when you have a form that is scrollable, as focusing the element will scroll that element into view. This is something that react-hook-form does, but it only works with input elements. One idea could be to pass a ref to some metadata of the field and then be able to access that metadata after validation occurs. Then I could add my own focus/scroll implementation:
|
Beta Was this translation helpful? Give feedback.
-
Does anyone have news about this? I would gladly provide a PR that changes this, but I don't understand the reasoning yet. Can we always trigger that, regardless of any changes being applied between two submit attempts? |
Beta Was this translation helpful? Give feedback.
-
@Balastrong @crutchcorn would be really cool if we could get an update on this. what's the recommended approach or is it straight up not feasible right now? |
Beta Was this translation helpful? Give feedback.
-
another usecase for focus-management: when adding a new entry to an array field with |
Beta Was this translation helpful? Give feedback.
-
With the most recent version of TanStack Form, this is how I solved it:
|
Beta Was this translation helpful? Give feedback.
-
The use-case that landed me here is a combo input, for which I wanted to unfocus (blur) the input on selection. I think it would be cool to have an API to do that. |
Beta Was this translation helpful? Give feedback.
-
Apologies y'all; I genuinely thought there was an A11Y issue with implementing this pattern. I was corrected today and as-such have documented how you can do so in your own projects: https://tanstack.com/form/latest/docs/framework/react/guides/focus-management FWIW we've been able to do this for ages but have not documented its capabilities due to my misunderstanding of the A11Y concerns. |
Beta Was this translation helpful? Give feedback.
Apologies y'all; I genuinely thought there was an A11Y issue with implementing this pattern. I was corrected today and as-such have documented how you can do so in your own projects:
https://tanstack.com/form/latest/docs/framework/react/guides/focus-management
FWIW we've been able to do this for ages but have not documented its capabilities due to my misunderstanding of the A11Y concerns.