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: support auxiliary clicks #45

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

Conversation

marcusforsberg
Copy link
Contributor

Hi Tim,

A colleague of mine noticed that the card component (which we're using heavily in our projects, thanks again!) doesn't support auxiliary clicks, i.e clicking with the middle mouse button or scroll wheel to open in a new tab.

This PR fixes this using onAuxClick.

I added this to the existing useRedundantClick hook; I guess the alternative would be to create a separete hook, but that hook would need to be passed the targetRef from useRedundantClick in order to work, so I opted for the simpler route of doing both events in the same hook. Let me know if you'd prefer the other option and I can adjust this PR accordingly. 😊

Copy link

vercel bot commented Aug 13, 2024

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

Name Status Preview Comments Updated (UTC)
radix-card-storybook-vcuo ✅ Ready (Inspect) Visit Preview 💬 Add feedback Aug 13, 2024 0:27am

@timhettler
Copy link
Owner

Thank you for your contribution, @marcusforsberg! I will review this PR sometime this week.

Copy link
Owner

@timhettler timhettler left a comment

Choose a reason for hiding this comment

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

Thanks again for your contribution. I did a quick test and it seems fine to remove the event.button guard but please do let me know if there was a specific reason you implemented it.

Comment on lines +43 to +45
if (event.button !== 1) {
return;
}
Copy link
Owner

Choose a reason for hiding this comment

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

My concern is that this is too specific for a library... Is this guard really necessary? Is there a downside to letting all aux events pass through?

Copy link
Contributor Author

@marcusforsberg marcusforsberg Aug 29, 2024

Choose a reason for hiding this comment

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

This is so that the handler specifically only handles middle mouse clicks. I believe if we removed it, it would start firing on the other mouse buttons as well (right click, browser back, browser forward), as per this list: https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/button#value (since the auxclick event fires for all non-primary mouse buttons).

That said I honestly only learned about the existence of auxclick when I set out to implement this, so I am in no way an expert! 😄

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.

2 participants