-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make clicking an external link in Firefox close the popup (#38)
* Update external links so that they close the popup in Firefox * Make PR deep links actual link elements that will close the popup
- Loading branch information
Showing
6 changed files
with
69 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import React from 'react'; | ||
import { tabs } from 'webextension-polyfill'; | ||
|
||
type ExternalLinkProps = { | ||
children: React.ReactNode; | ||
className?: string; | ||
href?: string; | ||
onClick?: () => any; | ||
title?: string; | ||
}; | ||
|
||
export const ExternalLink = ({ children, className, href, onClick, title }: ExternalLinkProps) => { | ||
return ( | ||
<a | ||
className={className} | ||
href={href} | ||
rel="noreferrer noopener" | ||
target="_blank" | ||
title={title} | ||
onClick={async e => { | ||
// Opening external links in Firefox will not cause the popup to automatically close, | ||
// so we must manually close it. | ||
|
||
// Closing the popup window before the link has finished opening will cause Firefox to open | ||
// the link in a new window instead of in a new tab. In order to prevent this, we manually | ||
// open the link in a new tab and await that, then close the popup window afterwards. | ||
e.preventDefault(); | ||
|
||
if (onClick) { | ||
await onClick(); | ||
} | ||
if (href) { | ||
await tabs.create({ url: href }); | ||
} | ||
|
||
window.close(); | ||
}} | ||
> | ||
{children} | ||
</a> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters