prismicio / prismic-react

React components and hooks to fetch and present Prismic content
https://prismic.io/docs/technologies/homepage-reactjs
Apache License 2.0
154 stars 40 forks source link

feat(PrismicLink): automatically set `target="_blank" rel="noopener noreferrer"` when `href` is external #147

Closed angeloashmore closed 2 years ago

angeloashmore commented 2 years ago

Types of changes

Description

This PR adds functionality to automatic set target="_blank" rel="noopener noreferrer" when href is an external URL.

<PrismicLink href="https://example.com">External</PrismicLink>
// <a href="https://example.com" target="_blank" rel="noopener noreferrer">External</a>

This behavior applies to both the href and field props. In the following example, assume doc.data.linkField resolves to an external URL.

<PrismicLink field={doc.data.linkField}>External</PrismicLink>
// <a href="https://example.com" target="_blank" rel="noopener noreferrer">External</a>

target and rel can always be overriden by passing these props directly.

<PrismicLink href="https://example.com" target={undefined}>
  External
</PrismicLink>;
// <a href="https://example.com">External</a>

<PrismicLink href="https://example.com" rel="help">
  External
</PrismicLink>;
// <a href="https://example.com" target="_blank" rel="help">External</a>

This functionality was intended to ship with the initial <PrismicLink> releaes, but it was accidentally left out.

Checklist:

🦮

codecov-commenter commented 2 years ago

Codecov Report

Merging #147 (4daf7fe) into master (966c792) will not change coverage. The diff coverage is 100.00%.

@@           Coverage Diff           @@
##           master     #147   +/-   ##
=======================================
  Coverage   92.06%   92.06%           
=======================================
  Files          18       18           
  Lines         315      315           
  Branches       74       74           
=======================================
  Hits          290      290           
  Misses          5        5           
  Partials       20       20           
Impacted Files Coverage Δ
src/PrismicLink.tsx 94.73% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 966c792...4daf7fe. Read the comment docs.

github-actions[bot] commented 2 years ago

size-limit report 📦

Path Size
dist/index.js 5.31 KB (+0.1% 🔺)
dist/index.cjs 6.83 KB (+0.09% 🔺)