-
Notifications
You must be signed in to change notification settings - Fork 50.5k
Add setTimeout to AutoFocusMixin. #1518
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
Conversation
|
I'm unable to repro this myself: http://jsfiddle.net/fCF45/1/ Are you sure you're not delaying attaching to the document yourself? |
|
The following code provides a fallback for when the DOM cannot be focused (presumably because it's not yet attached to the document). It would be possible to avoid trial-and-error but it would put older browsers (including IE8/9) at a disadvantage as But personally I'm not feeling good about it without a real use-case. |
|
That's interesting. I am adding components when I receive data regarding a screen that adds field elements and switches over to that in terms of visibility. I can't reproduce it in JSFiddle either but I can reproduce it in my app. As for your code, it does also solve the problem, but it appears IE8/IE9 don't support it. http://caniuse.com/#search=requestAnimationFrame |
|
Hmm, that's weird, I couldn't find anything immediately off about your setup (also, awesome GIF!). You're running React 0.10 I assume? As for |
|
Ah right, I didn't check that there was a polyfill for |
|
Could you add the following to |
|
|
|
Right, looking at your GIF again (again, awesome!), I think I know what the problem is. Your window is not focused when the DOM is mounted and thus the autofocus fails. Try manually loading your page (or just refreshing) and see if it helps (which is supported by your last comment). |
|
Hmm, doing with what I can in Atom Shell, it doesn't seem to have any effect. This problem also occurs when new buffers are created and switched over at the same time. For instance, the message field should have been focused right after I performed |
|
Hmm, intuitively it seems like a defect in Atom Shell. If it's possible for you to try it in the browser, then that would provide a definitive answer. However, seeing as it never manages to autofocus at all, and it's running in what looks like Chrome, it seems to me that Atom Shell is at fault here. It doesn't make sense that |
|
I've also encountered this in the past and added a setTimeout to fix: I don't have repro steps handy though. |
|
@kramerc One final test on my behalf for today if you please, in |
|
@syranide Browserifying my code (with small modifications as I needed to stub the required Edit: Turns out I had a |
|
@kramerc It's really interesting though that it doesn't even work in Chrome for you, as I mentioned, your code is simple enough and I couldn't find anything suspicious in it, but it works in the fiddle... this is weird. Huge thanks helping debug this. |
|
@syranide Thanks for helping, this problem is weird indeed. Should I update this pull request to use |
|
@kramerc I defer that decision to some official dev (but please keep it open). Personally I feel like it would be good to know what's actually wrong so that we could fix it at the source. However, from a practical standpoint, this is going to be an ongoing problem and I'm fairly certain that even if we conclusively find the source of the problem, that it wouldn't lead to an actionable fix (telling people they're doing it wrong without an actionable fix will just leave Given that we can use I think there is a theoretical downside to having the fallback in-terms of inputs fighting for focus, realistically though it's a "bad situation" and there's no right answer (a deterministic result would be preferable, but hardly of great importance). Again, I defer to some official dev, but that would be my take on the situation. |
|
@syranide Alright, I'll keep this open. I added a log statement to see what |
|
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks! |
|
example test case : http://jsfiddle.net/fCF45/3/ |
|
@bmeck If I'm reading the code correctly, that is a different issue and one that we can't solve as there is no DOM event to signal when an element has become visible. |
|
@syranide I am unsure, don't see any simple test cases if you have a better one. If the element is on the DOM and is visible it should focus() properly. I've a lot of experience in the area. |
|
The problem remains but I'm adding the needs-revision label because this can't go in as-is. |
|
Not exactly sure what @sebmarkbage is referring to, but I imagine we would want to use |
|
I'll go ahead and 👍 this, it is has started occurring consistently across our entire app in Chrome (I'm confident I've made no related change). I use this PR as a workaround for now and it seems to work well. |
|
@sebmarkbage What needs to be changed? |
|
@kramerc Thinking about it briefly, I imagine we want to guarantee that only one
...is.also a possibility where we might get the best of both worlds (although consistent behavior/timing across browsers might be preferable). |
|
I don't think this plugin even exists anymore. Regardless, merge conflicts and no comments in six months, closing. |


This ensures the element gets focused after the component is mounted. Without it, the element may not be focused as the browser hasn't finished rendering it, an issue which I encountered.