Skip to content

Commit

Permalink
Merge pull request #78 from nicolethoen/fix_href_onclick
Browse files Browse the repository at this point in the history
fix: address regression when onclick and href provided
  • Loading branch information
nicolethoen authored Jan 17, 2025
2 parents 7738f40 + bb176fe commit e8eb0e1
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions packages/module/src/components/CatalogTile/CatalogTile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,24 @@ export class CatalogTile extends React.Component<CatalogTileProps> {
private handleClick = (e: React.FormEvent<HTMLInputElement> | React.MouseEvent<Element, MouseEvent>) => {
const { onClick, href } = this.props;

if (!href) {
e.preventDefault();
} else {
if ("type" in e && e.type === "click" && onClick) {
// It's a MouseEvent
const mouseEvent = e as React.MouseEvent<Element, MouseEvent>;
if (
mouseEvent.metaKey || // Cmd key (Mac)
mouseEvent.ctrlKey || // Ctrl key
mouseEvent.shiftKey // Shift key
) {
window.open(href, '_blank');
return;
}
} else if (href){
window.open(href, '_blank');
}

if (onClick) {
onClick(e);
}
}
};

private renderBadges = (badges: React.ReactNode[]) => {
Expand Down

0 comments on commit e8eb0e1

Please sign in to comment.