Skip to content

relatedTarget missing from focus and blur events #855

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

Closed
jondkoon opened this issue Mar 6, 2018 · 8 comments
Closed

relatedTarget missing from focus and blur events #855

jondkoon opened this issue Mar 6, 2018 · 8 comments

Comments

@jondkoon
Copy link

jondkoon commented Mar 6, 2018

Do you want to request a feature or report a bug?
Bug

What is the current behavior?
When using handlers for onFocus and onBlur the relatedTarget property is missing from event.nativeEvent

If the current behavior is a bug, please provide the steps to reproduce:
Checkout this glitch: https://glitch.com/edit/#!/rnw-relatedtarget-bug

  • Tab through the buttons and observe that the relatedTarget is undefined when the event is normalized by react-native-web (check the console output)

What is the expected behavior?

Environment (include versions). Did this work in previous versions?
It looks like the issue was introduced with this commit: b4e4bfb#diff-e1a663dbcbd141f6fa72d76ecc2260ac

  • React Native for Web (version): 0.5.1
  • React (version): 16.2
@necolas
Copy link
Owner

necolas commented Mar 6, 2018

I don't think it's part of the React Native API so I'm curious what you need it for

@jondkoon
Copy link
Author

jondkoon commented Mar 6, 2018

We might be able to work around it. @sidhu663 should have some thoughts.

@sidhu663
Copy link

sidhu663 commented Mar 6, 2018

We're currently using this for focus management. We keep track of the focusable nodes within a modal and if the relatedTarget on a blur is outside the focusable set, we know that it's a focusout. I don't believe React Native has an onFocusOut since onBlur bubbles so I'm not sure how it could be determined whether the blur will result in a focus loss or not without the related target.

Maybe it's possible to use document.activeElement but it seems that the body has focus during the blur phase before the focus on the target happens which we can't capture within a component

@necolas
Copy link
Owner

necolas commented Mar 6, 2018

Perhaps you could look into doing this outside of React / React Native? That's how this library juggles some focus related tasks that need to happen out of tree, and it's how PlayStation implemented controls for focus-based UIs with RNW. Also worth noting that OSS focus traps don't rely on relatedTarget https://github.com/davidtheclark/focus-trap

@jondkoon
Copy link
Author

jondkoon commented Mar 7, 2018

Thanks for the info. I'll look into working around this today.

@necolas
Copy link
Owner

necolas commented Mar 22, 2018

Any follow up?

@jondkoon
Copy link
Author

We worked around it by using addEventListener in the ref callback. Thanks for taking a look!

@necolas
Copy link
Owner

necolas commented Mar 22, 2018

Ok

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

Successfully merging a pull request may close this issue.

3 participants