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

Middle mouse button click does not open link in new tab when using Safari #1772

Closed
raphaelbeckmann opened this issue Jan 19, 2024 · 11 comments · Fixed by #1908
Closed

Middle mouse button click does not open link in new tab when using Safari #1772

raphaelbeckmann opened this issue Jan 19, 2024 · 11 comments · Fixed by #1908
Labels
react Related to the react adapter

Comments

@raphaelbeckmann
Copy link

Version:

  • @inertiajs/react version: 1.0.14

Describe the problem:

Clicking an InertiaLink with the middle mouse button opens the page in the same tab.
I would expect it to behave like a normal a link, which opens the page in a new tab when using the middle mouse button.

Steps to reproduce:

Open https://inertiajs.com in Safari and click on a link using the middle mouse button. Result: It opens in the current tab, not a new tab.
Open https://inertiajs.com in Chrome and click on a link using the middle mouse button. Result: It opens in a new tab.

@raphaelbeckmann raphaelbeckmann added the react Related to the react adapter label Jan 19, 2024
@shengslogar
Copy link

Interestingly, this seems to be isolated to the React wrapper (which, as you referenced, inertiajs.com is built on) and doesn't affect Vue. The Ping CRM demo app uses the Vue adapter and works as expected in Safari.

Comparing the Vue and React link components doesn't yield anything obvious. Wondering if it has something to do with some underlying React thing.

@derrickreimer
Copy link
Contributor

I'm attempting to reproduce -- do you happen to have OS/browser versions where you observed this behavior?

@shengslogar
Copy link

Hey @derrickreimer, I just repro-ed this issue in Safari on inertiajs.com using my MX Master's middle button. Chrome and Firefox work as expected.

  • macOS 14.5 Sonoma
  • Safari 17.5 (19618.2.12.11.6)
  • Chrome 126.0.6478.63
  • Firefox 127.0.1

@derrickreimer
Copy link
Contributor

Pardon my ignorance 😅 is "middle click" a different action than Command+Click (on macOS)?

@shengslogar
Copy link

Yes! Command + Click (macOS) = Ctrl + Click (Windows) which is simply a modifier key + a normal click. Middle click is an entirely separate event. Looks like in JavaScript this is considered an auxclick. I never use the middle click button myself so this is a learning experience for me too!

For the vast majority of browsers that map middle click to opening a link in a new tab, including Firefox, it is possible to cancel this behavior by calling preventDefault() from within an auxclick event handler.

https://developer.mozilla.org/en-US/docs/Web/API/Element/auxclick_event#preventing_default_actions

@shengslogar
Copy link

Interestingly, it looks like there's no way to trigger middle clicks on macOS with the default trackpad or Magic Mouse, but apart from finding a mouse with a middle click button (triggered by pressing down on the scroll wheel), there are utilities that allow you to simulate. https://github.com/artginzburg/MiddleClick-Sonoma Oh, the edge cases!

@derrickreimer
Copy link
Contributor

Very interesting! It looks like there's a long standing WebKit bug that causes onclick to fire for aux clicks :( https://bugs.webkit.org/show_bug.cgi?id=22382. I don't believe there's technically a way to differentiate an aux click from a normal click in Safari (until this bug is fixed).

@derrickreimer
Copy link
Contributor

Closing this one since it's not actionable on our part. If Safari fixes the bug, this one should heal itself.

@shengslogar
Copy link

Reported in 2008, oof. Were you able to figure out why middle click with the Vue.js wrapper (http://demo.inertiajs.com) works in Safari?

@derrickreimer
Copy link
Contributor

derrickreimer commented Jun 24, 2024

Ohh I may have spoken too soon! It appears there's a button prop on MouseEvent that we could theoretically key off of in the intercept logic: https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/button#value (I haven't confirmed this, but perhaps by default Vue doesn't trigger the click handlers on middle click in Safari, unlike React).

@derrickreimer derrickreimer reopened this Jun 24, 2024
@shengslogar
Copy link

You're on to something!

https://codepen.io/shengslogar/pen/rNgKVGL

Safari left click:
Dialog saying "click: 0"

Safari middle click:
Dialog saying "click: 1"

Firefox left click:
Dialog saying "click: 0"

Firefox middle click:
Dialog saying "auxclick"

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

Successfully merging a pull request may close this issue.

3 participants