downshift: [react-native] Button props - Cannot read property activeElement of undefined
downshiftversion: 1.28.0nodeversion: 8.5.0npm(oryarn) version: 5.6.0react-nativeversion: 0.52.0reactversion: 16.2.0
Relevant code or config
What you did: Hey! tried to use the new and experimental react-native version (Thanks for that!), With Button instead of TextInput as the trigger.
What happened:
Cannot read property activeElement of undefined error has thrown.

Reproduction repository: https://github.com/eyalcohen4/downshift-react-native-bug
Problem description:
I think its related to the access attempt for document property of environment object, while it’s missing on react-native when I print environment.
Suggested solution:
Check if we are in react-native env using isReactNative before this condition -
if ( !isReactNative() && this.props.environment.document.activeElement === this.props.environment.document.body ) { event.target.focus() }
Will be happy to make a PR if it looks like the right solution. cc @kentcdodds @eliperkins
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Comments: 22 (16 by maintainers)
Commits related to this issue
- fix(native): focus input on button clicked (#334) — committed to eyalcohen4/downshift by deleted user 6 years ago
- fix(native): focus input on button clicked (#334) — committed to eyalcohen4/downshift by deleted user 6 years ago
- fix(native): focus input on button clicked (#334) — committed to eyalcohen4/downshift by deleted user 6 years ago
- fix(native): focus input on button clicked (#334) — committed to eyalcohen4/downshift by deleted user 6 years ago
- fix(native): focus input on button clicked (#334) — committed to eyalcohen4/downshift by deleted user 6 years ago
- fix(native): access error on document for react native (#451) <!-- Thanks for your interest in the project. Bugs filed and PRs submitted are appreciated! Please make sure that you are familiar ... — committed to downshift-js/downshift by samuelfullerthomas 6 years ago
- fix(native): access error on document for react native (#451) <!-- Thanks for your interest in the project. Bugs filed and PRs submitted are appreciated! Please make sure that you are familiar ... — committed to Rendez/downshift by samuelfullerthomas 6 years ago
TREVOR!!! I miss you already buddy!
This is great. I don’t think you’re doing anything wrong. If you could dig a little further to see what’s going on then we can get that error fixed.
As for an example, I’m not very into the react native world, but I think that a snack.expo.io link would be sweet 😃
Copied the
axiosexample (http://downshift.netlify.com/?selectedKind=Examples&selectedStory=axios&full=0&addons=1&stories=1&panelRight=0), and found the port over to React Native to be pretty easy, but was surprised that any dropdown item I click (or anywhere I click) triggers thisActiveElementerror.Not sure what I’m doing wrong, but happy to add my basic example to the docs, because I don’t see any simple starter for a basic working setup with RN. Guessing it has to do with the ref like you mentioned above, but as far as I can tell, I’m doing everything the suggested way.
Get it, Cool. To summarize and make sure I understand - I’ll apply a
refas ingetRootPropsfor the input both on web and native, but for now will only use it (in order to refocus) when:button_handleClickcalled, we are in native environment, and arefexist.Let me know if you think or meant something different. Hope to make it by the weekend, Thanks for the help, I’m really enjoying using Downshift with react-native.