Skip to content

Commit

Permalink
Correctly handle link interactions on extension cards (#10406)
Browse files Browse the repository at this point in the history
  • Loading branch information
microbit-robert authored Mar 6, 2025
1 parent 5661e93 commit 625364a
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions react-common/components/controls/Card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,26 @@ export const Card = (props: CardProps) => {
tabIndex
} = props;


const handleLinkOrTriggerClick = (e: React.MouseEvent | React.KeyboardEvent) => {
if (e.target && (e.target as HTMLElement).tagName == "A") {
return;
}
e.preventDefault();
onClick();
}

const handleClick = (e: React.MouseEvent) => {
handleLinkOrTriggerClick(e);
}

const handleKeyDown = (e: React.KeyboardEvent) => {
const charCode = (typeof e.which == "number") ? e.which : e.keyCode;
if (charCode === /*enter*/13 || charCode === /*space*/32) {
handleLinkOrTriggerClick(e);
}
}

return <div
id={id}
className={classList("common-card", className)}
Expand All @@ -33,9 +53,9 @@ export const Card = (props: CardProps) => {
aria-labelledby={ariaLabelledBy}
aria-hidden={ariaHidden}
aria-label={ariaLabel}
onClick={onClick}
onClick={handleClick}
tabIndex={tabIndex}
onKeyDown={fireClickOnEnter}>
onKeyDown={handleKeyDown}>
<div className="common-card-body">
{children}
</div>
Expand Down

0 comments on commit 625364a

Please sign in to comment.