Skip to content

Commit

Permalink
fix(PrismicLink): only set target="_blank" when "Open in new window…
Browse files Browse the repository at this point in the history
…" is checked (#176)
  • Loading branch information
angeloashmore authored Feb 17, 2023
1 parent 5b49ad5 commit e74b4d6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 26 deletions.
1 change: 0 additions & 1 deletion src/PrismicLink.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,6 @@ const _PrismicLink = <
props.field &&
"target" in props.field &&
props.field.target) ||
(!isInternal && "_blank") ||
undefined;

const rel =
Expand Down
32 changes: 7 additions & 25 deletions test/PrismicLink.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ test("allow overriding default target", (t) => {
t.deepEqual(actual, expected);
});

test("if manually given _blank to target, use rel'noopener norefferer", (t) => {
test('if manually given _blank to target, use rel="noopener norefferer"', (t) => {
const field: prismicT.FilledLinkToWebField = {
url: "/url",
link_type: prismicT.LinkType.Web,
Expand All @@ -231,10 +231,10 @@ test("if manually given _blank to target, use rel'noopener norefferer", (t) => {
t.deepEqual(actual, expected);
});

test('if target is not explicitly provided and the URL is external, use target="_blank" and rel="noopener noreferrer"', (t) => {
test("if target is not provided and the URL is external, target is not set", (t) => {
const actual = renderJSON(<PrismicLink href="https://example.com" />);
const expected = renderJSON(
<a href="https://example.com" target="_blank" rel="noopener noreferrer" />,
<a href="https://example.com" target={undefined} rel={undefined} />,
);

t.deepEqual(actual, expected);
Expand Down Expand Up @@ -289,7 +289,7 @@ test("if URL is internal and internalComponent is given to the provider and the
test("if URL is external and no externalComponent is given, render an <a>", (t) => {
const actual = renderJSON(<PrismicLink href="https://example.com" />);
const expected = renderJSON(
<a href="https://example.com" rel="noopener noreferrer" target="_blank" />,
<a href="https://example.com" target={undefined} rel={undefined} />,
);

t.deepEqual(actual, expected);
Expand All @@ -299,13 +299,7 @@ test("if URL is external and externalComponent is given, render externalComponen
const actual = renderJSON(
<PrismicLink href="https://example.com" externalComponent={Link} />,
);
const expected = renderJSON(
<Link
href="https://example.com"
rel="noopener noreferrer"
target="_blank"
/>,
);
const expected = renderJSON(<Link href="https://example.com" />);

t.deepEqual(actual, expected);
});
Expand All @@ -316,13 +310,7 @@ test("if URL is external and externalComponent is given to the provider, render
<PrismicLink href="https://example.com" />
</PrismicProvider>,
);
const expected = renderJSON(
<Link
href="https://example.com"
rel="noopener noreferrer"
target="_blank"
/>,
);
const expected = renderJSON(<Link href="https://example.com" />);

t.deepEqual(actual, expected);
});
Expand All @@ -333,13 +321,7 @@ test("if URL is external and externalComponent is given to the provider and the
<PrismicLink href="https://example.com" externalComponent={Link} />
</PrismicProvider>,
);
const expected = renderJSON(
<Link
href="https://example.com"
rel="noopener noreferrer"
target="_blank"
/>,
);
const expected = renderJSON(<Link href="https://example.com" />);

t.deepEqual(actual, expected);
});
Expand Down

0 comments on commit e74b4d6

Please sign in to comment.