Skip to content

Commit

Permalink
Fixed issues with inability to open links in new window when clicking…
Browse files Browse the repository at this point in the history
… the external link icon in a card.
  • Loading branch information
anilnatha committed Nov 11, 2024
1 parent 8ee8cff commit 8182624
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
19 changes: 13 additions & 6 deletions src/components/Card/index.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { IconExternalLink } from "@nasa-jpl/react-stellar";
import { Pill } from "../../components/Pill";
import { Link } from "react-router-dom";

export type CardProps = {
description:string;
route:string;
title:string;
type:string;
url?:string;
url:string;
}

export const Card = ({
Expand All @@ -16,21 +17,27 @@ export const Card = ({
type,
url
}:CardProps) => {

const onClickExternalHandler = (event:React.SyntheticEvent) => {
// Stop Propgation of event to parent card element; otherwise,
// the user will be navigated to the parent card route
if(event && event.stopPropagation) event.stopPropagation();
}

return (
<a href={route}>
<Link to={route}>
<span className="unity-card">
<span className="header">
<span className="title">{title}</span>
{ url && <span className="icons">
<a href={url} target={"_blank"}><IconExternalLink /></a>
<span className="icons">
<Link to={url} target={"_blank"} onClick={ (e) => {onClickExternalHandler(e)}}><IconExternalLink /></Link>
</span>
}
</span>
<div className="description">{description}</div>
<div className="footer">
<Pill label={type}/>
</div>
</span>
</a>
</Link>
)
}
2 changes: 2 additions & 0 deletions src/routes/home/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,14 @@ function Home() {
route={"/health-dashboard"}
title="Health Dashboard"
type={"web"}
url={"/health-dashboard"}
/>,
<Card
description="Documentation to help become familiar with the Unity platform."
route={"https://unity-sds.gitbook.io/docs"}
title="Documentation (Gitbook)"
type={"web"}
url={"https://unity-sds.gitbook.io/docs"}
/>
);

Expand Down

0 comments on commit 8182624

Please sign in to comment.