Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: ButtonLink onClick handler #12935

Merged
merged 4 commits into from
May 18, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions src/components/Buttons/ButtonLink.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,26 @@ import { BaseLink, type LinkProps } from "@/components/Link"
import { type MatomoEventOptions, trackCustomEvent } from "@/lib/utils/matomo"

export type ButtonLinkProps = LinkProps &
Omit<ButtonProps, "toId" | "onClick"> & {
Omit<ButtonProps, "toId"> & {
customEventOptions?: MatomoEventOptions
}

const ButtonLink = ({ customEventOptions, ...props }: ButtonLinkProps) => {
const ButtonLink = ({
customEventOptions,
onClick,
...props
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm.. this is a little confusing since we're accepting an onClick, which could override the click handler per below, but we also have customEventOptions which wouldn't be used if onClick is provided...

@nhsz If we need to accept onClick here, should we merge it into the handleClick() function below? ie

const handleClick = () => {
  customEventOptions && trackCustomEvent(customEventOptions)
  onClick()
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nhsz @wackerow the underlying Button component already handles this logic. So I'd say, let's get rid of the onClick handler from this component completely and rely on the logic set in the button component. Otherwise, we are (and we were) duplicating this logic.

}: ButtonLinkProps) => {
const handleClick = () => {
customEventOptions && trackCustomEvent(customEventOptions)
}

return (
<Button as={BaseLink} activeStyle={{}} {...props} onClick={handleClick} />
<Button
as={BaseLink}
activeStyle={{}}
{...props}
onClick={onClick ? onClick : handleClick}
nhsz marked this conversation as resolved.
Show resolved Hide resolved
/>
)
}

Expand Down
Loading