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

Prevent default clicking on markdown preview links when using openLinksInNewTab #2718

Merged
merged 9 commits into from
Jan 10, 2023

Conversation

marywhite
Copy link
Contributor

Describe your changes here.

Closes #2717

MarkdownViewer accepts an openLinksInNewTab prop to ensure link previews open in a new tab. Because default is not prevented, navigation is also happening in the working tab.

I've also added gone ahead and added noopener noreferrer to the call to window.open s/o @mattcosta7

Screenshots

Before:

link-navigation-before.mov

After:

link-navigation-after.mov

Merge checklist

  • Added/updated tests
  • Added/updated documentation
  • Tested in Chrome
  • Tested in Firefox
  • Tested in Safari
  • Tested in Edge

Take a look at the What we look for in reviews section of the contributing guidelines for more information on how we review PRs.

@marywhite marywhite requested review from a team and mperrotti December 20, 2022 21:23
@changeset-bot
Copy link

changeset-bot bot commented Dec 20, 2022

🦋 Changeset detected

Latest commit: 43ef170

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@primer/react Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

// error when clicking the link above. The spy here captures this error
// and will assert that it is called only once, otherwise another error
// in this test has occurred
expect(spy).toHaveBeenCalledTimes(1)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This test was previously asserting the buggy behavior - now that we're not navigating the page (the call to window.open is mocked), we don't see any error.

Copy link
Contributor

@colebemis colebemis left a comment

Choose a reason for hiding this comment

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

Thank you 💖

@joshblack joshblack added the 💓collab a vibrant hub of collaboration label Jan 9, 2023
@joshblack joshblack enabled auto-merge (squash) January 9, 2023 16:48
auto-merge was automatically disabled January 9, 2023 17:08

Head branch was pushed to by a user without write access

@marywhite
Copy link
Contributor Author

@joshblack are you able to reenable auto-merge? pushed out a linting fix and I don't have access to merge 🙏

@joshblack
Copy link
Member

@marywhite on it!

@joshblack joshblack enabled auto-merge (squash) January 10, 2023 18:10
@joshblack joshblack merged commit 9cb0119 into primer:main Jan 10, 2023
@primer-css primer-css mentioned this pull request Jan 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
💓collab a vibrant hub of collaboration
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Links clicked from previews inside of MarkdownEditor open in both working and new tab
5 participants