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

feat: unstable_defaultAltClick link prop, no route change if enabled #1249

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

rmarscher
Copy link
Contributor

Fixes #1248.

Copy link

vercel bot commented Feb 19, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
waku ✅ Ready (Inspect) Visit Preview Feb 19, 2025 2:41pm

Copy link

codesandbox-ci bot commented Feb 19, 2025

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

@rmarscher
Copy link
Contributor Author

I think this is a draft until we create an e2e test.

Comment on lines +272 to +274
if (!isAltClick) {
event.preventDefault();
}
Copy link
Owner

Choose a reason for hiding this comment

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

Why can it be this?

if (isAltClick) {
  return;
}

Copy link
Contributor Author

@rmarscher rmarscher Feb 20, 2025

Choose a reason for hiding this comment

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

That skips the onClick prop. What do you think about firing the onClick prop first? React Router does that and then doesn't run the internal handler if the onClick calls preventDefault().
https://github.com/remix-run/react-router/blob/react-router%407.2.0/packages/react-router/lib/dom/lib.tsx#L628-L635

function handleClick(
  event: React.MouseEvent<HTMLAnchorElement, MouseEvent>
) {
  if (onClick) onClick(event);
  if (!event.defaultPrevented) {
    internalOnClick(event);
  }
}

Copy link
Owner

Choose a reason for hiding this comment

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

Oh, that looks great. Any drawbacks?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not that I can think of. It looks good to me. I'm traveling for the next few days so I probably won't push another update until the beginning of next week.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

It should be possible to open a Link in a new tab using browser default behavior
2 participants