bigskysoftware / bigskysoftware/htmx
Support default ctrl/cmd and shift click behavior for hx-get enhanced anchor elements
- Dominant language
- JavaScript
- Stars
- 49.4k
- Forks
- 1.7k
- Avg merge
- 3d 22h
- Merged PRs (30d)
- 30
Description
Hi,
as we all know, web browsers implement a default behavior when links are clicked with pressed **ctrl/cmd** keys or the **shift** key. With ctrl/cmd pressed, the page is opened in a new tab, with shift pressed, the page is opened in a new window. This is the behavior on almost all browsers and on almost all operating systems. It is expected by many users, especially power users.
Unfortunately this doesn't work in htmx apps on anchor elements with `hx-get` tag. No matter if ctrl/cmd or shift is pressed, a standard request in the same tab is made.
Filtering the event, e.g. with `hx-trigger="click[!ctrlKey]"`, doesn't work either since the default browser behavior is not applied in that case. This was already addressed in issue #1572 .
With `hx-boost` enhanced links, at least ctrl/cmd clicks work as expected. But shift-clicks still don't work. E.g. on the htmx.org homepage, a shift-click on "docs" doesn't open the docs in a new windows.
The shift click issue is not that important, but the ctrl/cmd really is, in my opinion. I am evaluating migrating a react app to htmx and the react app handles ctrl/cmd clicks correctly.
Is there a chance to add this to htmx? Or would it be possible for an extension to add this behavior?
Contributor guide
Assessment
This issue has not been assessed yet.