Skip to content

Commit ea9267e

Browse files
committed
fix: address regression when onclick and href provided
1 parent 7738f40 commit ea9267e

File tree

3 files changed

+16
-5
lines changed

3 files changed

+16
-5
lines changed

packages/module/patternfly-docs/content/examples/CatalogTile.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ import pfLogo6 from './pfLogo6.svg';
9494
<CogIcon />
9595
</CatalogTileBadge>
9696
]}
97+
onClick={()=>console.log("hi")}
9798
href="http://patternfly.org/v4"
9899
title="Patternfly-React"
99100
vendor="provided by Red Hat"

packages/module/patternfly-docs/generated/extensions/catalog-view/catalog-tile/react.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ pageData.examples = {
144144

145145
</Example>,
146146
'Link variant': props =>
147-
<Example {...pageData} {...props} {...{"code":"import React from 'react';\nimport { CatalogTile, CatalogTileBadge } from '@patternfly/react-catalog-view-extension';\nimport CogIcon from '@patternfly/react-icons/dist/esm/icons/cog-icon';\nimport pfLogo6 from './pfLogo6.svg';\n\nconst LinkVariant = () => (\n <CatalogTile\n id=\"simple-link-variant\"\n iconImg={pfLogo6}\n iconAlt=\"PatternFly logo\"\n badges={[\n <CatalogTileBadge title=\"Certified\">\n <CogIcon />\n </CatalogTileBadge>\n ]}\n href=\"http://patternfly.org/v4\"\n title=\"Patternfly-React\"\n vendor=\"provided by Red Hat\"\n description={\n 'This is a very, very long description that should be truncated after three lines. ' +\n 'Three lines is the default for cards without a footer. Cards with a footer are truncated after one line. Truncation function use is deprecated; please pass in a maxDescriptionLength of -1 to override it. ' +\n 'This has changed from PatternFly 3.'\n }\n />\n)","title":"Link variant","lang":"js","className":""}}>
147+
<Example {...pageData} {...props} {...{"code":"import React from 'react';\nimport { CatalogTile, CatalogTileBadge } from '@patternfly/react-catalog-view-extension';\nimport CogIcon from '@patternfly/react-icons/dist/esm/icons/cog-icon';\nimport pfLogo6 from './pfLogo6.svg';\n\nconst LinkVariant = () => (\n <CatalogTile\n id=\"simple-link-variant\"\n iconImg={pfLogo6}\n iconAlt=\"PatternFly logo\"\n badges={[\n <CatalogTileBadge title=\"Certified\">\n <CogIcon />\n </CatalogTileBadge>\n ]}\n onClick={()=>console.log(\"hi\")}\n href=\"http://patternfly.org/v4\"\n title=\"Patternfly-React\"\n vendor=\"provided by Red Hat\"\n description={\n 'This is a very, very long description that should be truncated after three lines. ' +\n 'Three lines is the default for cards without a footer. Cards with a footer are truncated after one line. Truncation function use is deprecated; please pass in a maxDescriptionLength of -1 to override it. ' +\n 'This has changed from PatternFly 3.'\n }\n />\n)","title":"Link variant","lang":"js","className":""}}>
148148

149149
</Example>,
150150
'With multiple icon badges': props =>

packages/module/src/components/CatalogTile/CatalogTile.tsx

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,24 @@ export class CatalogTile extends React.Component<CatalogTileProps> {
6363
private handleClick = (e: React.FormEvent<HTMLInputElement> | React.MouseEvent<Element, MouseEvent>) => {
6464
const { onClick, href } = this.props;
6565

66-
if (!href) {
67-
e.preventDefault();
68-
} else {
66+
if ("type" in e && e.type === "click" && onClick) {
67+
// It's a MouseEvent
68+
const mouseEvent = e as React.MouseEvent<Element, MouseEvent>;
69+
if (
70+
mouseEvent.metaKey || // Cmd key (Mac)
71+
mouseEvent.ctrlKey || // Ctrl key
72+
mouseEvent.shiftKey // Shift key
73+
) {
74+
window.open(href, '_blank');
75+
return;
76+
}
77+
} else if (href){
6978
window.open(href, '_blank');
7079
}
80+
7181
if (onClick) {
7282
onClick(e);
73-
}
83+
}
7484
};
7585

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

0 commit comments

Comments
 (0)