-
-
Notifications
You must be signed in to change notification settings - Fork 637
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 on an input generated from button press #742
Comments
Focusing on the input after a button click isn't "auto focus", that's an explicit focus. "Auto focus" means, automatically when the page loads. |
Got it, thanks very much! I'll disable the rule for these lines in that case. |
To be clear, you should not disable the rule - |
In this case I'm only mounting the input after the button is pressed, e.g:
The search input isn't autofocussed on page load as it doesn't exist yet. After clicking the button, the input is created and is autofocussed. Would you still consider this an explicit focus? |
I would consider this a misuse of |
The warning still shows here when using autoFocus as a prop. Another warning is thrown inside the component when it's actually used.
Isn't this basically what React is already doing? This issue discusses how autoFocus is implemented via polyfill with .focus() on mount, rather than passed as a DOM attribute. What would be the advantage of doing this explicitly? |
Fair point - that kind of calls into question this entire lint rule. @jessebeach? |
I have a single input field for typing a search term which is only added to the DOM after interacting with a dedicated 'show search' button. I can't think of a reason why someone pressing on this button wouldn't want to then immediately focus on the input, but maybe I'm missing something! Please could you advise if the no-autofocus rule would still be valid here?
The text was updated successfully, but these errors were encountered: