-
Notifications
You must be signed in to change notification settings - Fork 47.3k
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
AutoFocus attribute is not triggered on render #5534
Comments
@omuryolcu In the past, this has been because something else on the page is stealing focus. Questions like this should be on StackOverflow, etc. as the functionality is very likely not broken. |
@yaycmyk hey Evan, well this is not a question, it's a bug report IMHO. For me it didn't work and I could only make it work like that. If you guys would prove me wrong, I would be delighted however I'm strongly convinced that this is a bug. It would be unfair not to report it :) |
You know what, sorry I misread your initial post. The intended behavior is only to move focus on first render, and this is consistent with the HTML spec for So it's not a bug and your workaround is one of a few possibilities if you want it to remain constantly focused. |
Hey Evan :) @yaycmyk So maybe it's of use to somebody :) Thank you! |
As mentioned, this seems like it's in line with the spec. There may be some inconsistencies because I think we fake it. Focus is one of those things that is really tricky to do declaratively because it's part of a shared global state. If 2 unrelated components declare that they should be focused in a single render pass, who is right? So we give you the hooks to manage that state yourself but we won't do it for you. Sorry that this has cause you troubles! |
Hey Paul! @zpao Thank you very much for your attention. |
I know I'm a couple years late to this discussion but I just found this after experiencing my own similar issues. I understand that you want it to be in line with spec. That's fine. It would be great if you added the option to focus on render (could be just One particular case that I need this for is that I have a full screen editor with a few inputs. I want it to focus on whichever input is the first to not be filled out. This is simple enough with just plain The issue is that the full screen editor has multiple pages, each with the same input. When I change the page, the inputs themselves are not re-rendered because they haven't changed. Thus no focus happens. I do plan to use a similar solution to the one found above, and it would be great to see if this could be added to React. I'd be happy to do a PR if y'all agree it should be in there. (Apologies if something like this was already added) |
Hello,
The autoFocus attribute is not triggered on a render therefor it is impossible to change the focus with that attribute if there are multiple fields.
Currently the only way to change the focus is to give the input a ref and change it on componentDidUpdate()
The autoFocus attribute will only work on the initial render.
The text was updated successfully, but these errors were encountered: