Skip to content

Commit 5795d93

Browse files
authored
Merge pull request #8087 from piyushtripathi9424/fix-meet-five-layout-shift
fix: remove nested anchors in AdventuresVol and HandbookCard
2 parents 7e1bd26 + bd0595d commit 5795d93

2 files changed

Lines changed: 46 additions & 23 deletions

File tree

‎src/components/AdventuresVol/index.js‎

Lines changed: 42 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,52 @@
11
import React from "react";
2+
import { Link } from "gatsby";
23
import { HiOutlineChevronRight } from "@react-icons/all-files/hi/HiOutlineChevronRight";
34
import { AdventuresVolWrapper } from "./adventures-vol.style";
45

56
const AdventuresVol = ({ title, description, to, image }) => {
7+
const isExternalOrStatic =
8+
to &&
9+
(to.startsWith("http://") ||
10+
to.startsWith("https://") ||
11+
to.split("?")[0].split("#")[0].toLowerCase().endsWith(".pdf") ||
12+
to.startsWith("mailto:"));
13+
14+
const isMailTo = to && to.startsWith("mailto:");
15+
16+
const cardContent = (
17+
<div className="handbook__card">
18+
<h1 className="handbook__card--head">{title}</h1>
19+
<div className="handbook__card--line"></div>
20+
<img src={image} />
21+
<p className="handbook__card--para">{description}</p>
22+
{to && (
23+
<div className="handbook__card--lm__container">
24+
<span className="handbook__card--lm">
25+
Read More <HiOutlineChevronRight />
26+
</span>
27+
</div>
28+
)}
29+
</div>
30+
);
31+
632
return (
733
<AdventuresVolWrapper>
8-
<a href={to} className="handbook__card--main">
9-
<div className="handbook__card">
10-
<h1 className="handbook__card--head">{title}</h1>
11-
<div className="handbook__card--line"></div>
12-
<img src={image} />
13-
<p className="handbook__card--para">
14-
{description}
15-
</p>
16-
{to && (
17-
<div className="handbook__card--lm__container">
18-
<a href={to} className="handbook__card--lm">
19-
Read More <HiOutlineChevronRight />
20-
</a>
21-
</div>
22-
)}
23-
</div>
24-
</a>
34+
{!to ? (
35+
<div className="handbook__card--main">{cardContent}</div>
36+
) : isExternalOrStatic ? (
37+
<a
38+
href={to}
39+
className="handbook__card--main"
40+
target={isMailTo ? undefined : "_blank"}
41+
rel={isMailTo ? undefined : "noreferrer"}
42+
>
43+
{cardContent}
44+
</a>
45+
) : (
46+
<Link to={to} className="handbook__card--main">
47+
{cardContent}
48+
</Link>
49+
)}
2550
</AdventuresVolWrapper>
2651
);
2752
};

‎src/components/HandbookCard/index.js‎

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,16 @@ import { HandbookCardWrapper } from "./HandbookCard.style";
66
const HandbookCard = ({ title, description, to }) => {
77
return (
88
<HandbookCardWrapper>
9-
<Link to={to} class="handbook__card--main">
9+
<Link to={to} className="handbook__card--main">
1010
<div className="handbook__card">
1111
<h1 className="handbook__card--head">{title}</h1>
1212
<div className="handbook__card--line"></div>
13-
<p className="handbook__card--para">
14-
{description}
15-
</p>
13+
<p className="handbook__card--para">{description}</p>
1614
{to && (
1715
<div className="handbook__card--lm__container">
18-
<a href={to} className="handbook__card--lm">
16+
<span className="handbook__card--lm">
1917
Read More <HiOutlineChevronRight />
20-
</a>
18+
</span>
2119
</div>
2220
)}
2321
</div>

0 commit comments

Comments
 (0)