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

Add environment prop #365

Merged
merged 4 commits into from
Feb 6, 2021
Merged

Add environment prop #365

merged 4 commits into from
Feb 6, 2021

Conversation

voluntadpear
Copy link
Contributor

I've ran into a use case where the focus between tabs wasn't properly handled while navigating using the arrow keys due to having react-tabs rendered on an iframe.

Inspired by downshift, this PR adds an environment prop to allow users to specify a different window if they need to.

// https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/12733599
canUseActiveElement = false;

function determineCanUseActiveElement(environment) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wrapping this into a function that runs only once (since initially canUseActiveElement is undefined) to be able to use the environment from the props instead of assuming window.

@@ -1,6 +1,3 @@
/**
* @jest-environment node
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Allowed this tests to run on jsdom so that window can be used. All tests keep working.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did accessing window crash the test? Or how did you notice this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it was because of having the tests failing on CI: https://travis-ci.org/github/reactjs/react-tabs/builds/753987091

Copy link
Collaborator

@danez danez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we have to make sure that window is not required, so that tests still work without window and more important possible server-side rendering does not crash, because window is not available there.
So before accessing window there always needs to be a typeof window !== 'undefined'.
By quickly thinking about it I would try to change the code so that there is no default value and the new determineCanUseActiveElement should fallback to window if no environment given and also handle the case where environment not set and window also not available.

@voluntadpear voluntadpear requested a review from danez January 13, 2021 18:14
@voluntadpear
Copy link
Contributor Author

@danez Thanks for reviewing! I added the checks and reverted the Node test to make it work as before.

@danez danez merged commit d6fd355 into reactjs:master Feb 6, 2021
@danez
Copy link
Collaborator

danez commented Feb 6, 2021

🎉 This PR is included in version 3.2.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@danez danez added the released label Feb 6, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 28, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants