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

autofocus doesn't work when "autofocus" property is changed. #1692

Closed
acierto opened this issue Apr 28, 2017 · 7 comments
Closed

autofocus doesn't work when "autofocus" property is changed. #1692

acierto opened this issue Apr 28, 2017 · 7 comments

Comments

@acierto
Copy link

acierto commented Apr 28, 2017

So basically autofocus is looking only at componentDidMount and never recalculated in componentDidUpdate

@cbergmiller
Copy link
Contributor

Could you explain you use case?
The behavior of autofocus is described in the docs here (it is only focused on mount).

@nortonwong
Copy link

This behavior also matches broader spec. In HTML and in React, it is intended that autofocus only applies on the initial mount.

To focus your Select component, store its ref and call ref.focus().

@dwoowb
Copy link

dwoowb commented Jan 12, 2018

@acierto did you end up finding a solution to this, I just came to the same conclusion as you.

@dwoowb
Copy link

dwoowb commented Jan 12, 2018

So in my particular case, I was conditionally assigning the disabled prop based on fetching data from an API. With autoFocus={true} handleInputFocus() is triggered only on initial mount as @nortonwong described but handleInputFocus() immediately returns if disabled is true. And like @acierto pointed out componentDidUpdate() doesn't consider autoFocus, only componentDidMount() so when disabled is updated to be false the input doesn't get focused.

Ultimately in my case I think react-select's behavior is fine as it makes sense that disabled should override autoFocus. If for whatever reason I need to continue to disable until my data is fetched then I may consider adjusting this lib to focus/open any time it goes from a disabled to enabled state (but not the inverse)

@acierto
Copy link
Author

acierto commented Jan 12, 2018

@dwoowb As authors of this lib decided to do it only on mount I basically went with @nortonwong solution.

And the answer on @cbergmiller question, I have the same user scenario as @dwoowb

@bladey
Copy link
Contributor

bladey commented May 27, 2020

Hello -

In an effort to sustain the react-select project going forward, we're closing old issues / pull requests.

We understand this might be inconvenient but in the best interest of supporting the broader community we have to direct our limited efforts to maintain the latest version.

If you feel this issue / pull request is still relevant and you'd like us to review it, please leave a comment and we'll do our best to get back to you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants