dioxus icon indicating copy to clipboard operation
dioxus copied to clipboard

Ctrl/cmd click does not open in a new tab/window

Open rogusdev opened this issue 1 year ago • 0 comments

Problem

Link elements are a tags in rendered html, but have a dioxus-prevent-default="onclick" which I assume is not looking at the ctrl/cmd state when clicked to replicate the normal browser behavior. https://support.mozilla.org/en-US/questions/1336268 is a discussion of this problem in general (dioxus is not the first and only framework with this issue, but it is fixable.)

If you are not familiar with this workflow: ctrl clicking a "normal" link on the vast majority of websites will open the link in a new browser tab/window, but not so with Link elements in a current dioxus site. Consistency with typical browser behavior/usage seems desirable. (Thus this issue is being tagged as a bug rather than feature request.)

It's easy enough to find where normal link behavior is blocked: https://github.com/DioxusLabs/dioxus/blob/472031d1f51557601797d1cb469f09e4f3e0ca71/packages/web/src/dom.rs#L84

And I believe this is where link clicking is replaced: https://github.com/DioxusLabs/dioxus/blob/472031d1f51557601797d1cb469f09e4f3e0ca71/packages/router/src/components/link.rs#L265

But I'm not sure how quite to work with the router and/or browser to handle this behavior properly on the web -- especially given dioxus's cross platform nature of desktop vs web, etc where ctrl click opening a new tab perhaps does not make sense except only in a browser. It seems like some kind of override is needed for web to handle this consistently with that the typical behavior unique for that platform (browsers). Given pointers on where the appropriate (i.e. acceptable to the team) place to make such an override would be, I'll happily attempt to make the changes myself.

Steps To Reproduce

  • dx new with router
  • dx serve that new app
  • open up http://localhost:8080/
  • ctrl click the "Go to blog" link at the top

Expected behavior

Ctrl clicking the "Go to blog" link should open in a new tab/window (depending on your browser config).

For comparison, go to https://www.google.com/ and ctrl click the "About" link in the top left, it will open in a new tab/window.

Environment:

  • App platform: web

Questionnaire

  • [x] I'm interested in fixing this myself but don't know where to start
  • [ ] I would like to fix and I have a solution
  • [ ] I don't have time to fix this right now, but maybe later

rogusdev avatar May 02 '24 13:05 rogusdev