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

Fix the onClick override logic #1489

Merged
merged 5 commits into from Jul 19, 2017
Merged

Fix the onClick override logic #1489

merged 5 commits into from Jul 19, 2017

Conversation

jacobdeichert
Copy link
Contributor

I took @KyleAMathews suggestion and looked into react-router's Link component handleClick logic. This solution is almost a direct copy/paste of the important parts that gatsby-link needs in order for the click logic to behave more as expected.

Now, cmd/ctrl-clicking opens links in a new tab, as expected! Also, target="_blank" now works too.

Fixes #1417

Solution is almost a direct copy/paste from react-router's Link
component (as suggested):
https://github.com/ReactTraining/react-router/blob/676e8ac14da780e9fbd32
7576971fe549f3d0b8c/packages/react-router-dom/modules/Link.js#L40-L43

Now, cmd/ctrl-clicking opens links in a new tab, as expected! Also,
target="_blank" now works.
@KyleAMathews
Copy link
Contributor

KyleAMathews commented Jul 13, 2017

@jacobdeichert
Copy link
Contributor Author

The gatsby-link package currently doesn't have a test setup. Should I add a test for this change?

Also, let me know if the code doesn't pass your desired style guide 👍

@KyleAMathews
Copy link
Contributor

Deploy preview failed.

Built with commit 980d098

https://app.netlify.com/sites/image-processing/deploys/5966c94a6f4c5074d8a1ddcd

@gatsbybot
Copy link
Collaborator

gatsbybot commented Jul 13, 2017

Deploy preview failed.

Built with commit 45dd1a3

https://app.netlify.com/sites/gatsbyjs/deploys/596ea3698ebdd92c5150f3be

@gatsbybot
Copy link
Collaborator

gatsbybot commented Jul 13, 2017

Deploy preview ready!

Built with commit 45dd1a3

https://deploy-preview-1489--using-drupal.netlify.com

@gatsbybot
Copy link
Collaborator

gatsbybot commented Jul 13, 2017

Deploy preview ready!

Built with commit 45dd1a3

https://deploy-preview-1489--gatsbygram.netlify.com

@KyleAMathews
Copy link
Contributor

Thanks for the fix! Looks like it's working now 🎉

Could you not break out the new code though into separate functions? There's very little code in the new functions so I think it makes things harder to follow.

@jacobdeichert
Copy link
Contributor Author

Sure thing! I'll adjust it 👍

@KyleAMathews
Copy link
Contributor

Oh also the checks for production and if we should handle the click or not don't have anything to do with each other. Put the checks on handling the clicks at the top of the function.

@jacobdeichert
Copy link
Contributor Author

Right, this whole onClick handler should be wrapped inside an if statement. I'll adjust

@@ -73,8 +55,27 @@ class GatsbyLink extends React.Component {
!e.ctrlKey &&
!e.shiftKey
) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

How's this looking to you now? :)

If I misunderstood your instructions, let me know and I can adjust further.

Note that I kept onClick && onClick(e) outside the if statement so that it still can be overridden if need be.

Copy link
Contributor

Choose a reason for hiding this comment

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

Nope, looks great! Just been traveling recently. Merging now and will be prepping new release soon, thanks!

@KyleAMathews KyleAMathews merged commit 1a71f26 into gatsbyjs:master Jul 19, 2017
@jacobdeichert
Copy link
Contributor Author

Yay! Thanks for merging @KyleAMathews 😄

@jlengstorf
Copy link
Contributor

Hiya @jakedeichert! 👋

This is definitely late, but on behalf of the entire Gatsby community, I wanted to say thank you for being here.

Gatsby is built by awesome people like you. Let us say “thanks” in two ways:

  1. We’d like to send you some Gatsby swag. As a token of our appreciation, you can go to the Gatsby Swag Store and log in with your GitHub account to get a coupon code good for one free piece of swag. (We’ve got t-shirts and hats, plus some socks that are really razzing our berries right now.)
  2. If you’re not already part of it, we just invited you to join the Gatsby organization on GitHub. This will add you to our team of maintainers. You’ll receive an email shortly asking you to confirm. By joining the team, you’ll be able to label issues, review pull requests, and merge approved pull requests.

If you have questions, please don’t hesitate to reach out to us: tweet at @gatsbyjs and we’ll come a-runnin’.

Thanks again! 💪💜

1 similar comment
@jlengstorf
Copy link
Contributor

Hiya @jakedeichert! 👋

This is definitely late, but on behalf of the entire Gatsby community, I wanted to say thank you for being here.

Gatsby is built by awesome people like you. Let us say “thanks” in two ways:

  1. We’d like to send you some Gatsby swag. As a token of our appreciation, you can go to the Gatsby Swag Store and log in with your GitHub account to get a coupon code good for one free piece of swag. (We’ve got t-shirts and hats, plus some socks that are really razzing our berries right now.)
  2. If you’re not already part of it, we just invited you to join the Gatsby organization on GitHub. This will add you to our team of maintainers. You’ll receive an email shortly asking you to confirm. By joining the team, you’ll be able to label issues, review pull requests, and merge approved pull requests.

If you have questions, please don’t hesitate to reach out to us: tweet at @gatsbyjs and we’ll come a-runnin’.

Thanks again! 💪💜

@jacobdeichert
Copy link
Contributor Author

@jlengstorf wow, this is so nice! Thank 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

Successfully merging this pull request may close these issues.

None yet

4 participants