Skip to content

Commit 11b6c77

Browse files
committed
fix ctrl click on links
1 parent 0fe17fb commit 11b6c77

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

src/reactpy_router/components.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,10 @@ def _link(attributes: dict[str, Any], *children: Any) -> VdomDict:
6363
# https://github.com/reactive-python/reactpy/pull/1224
6464
current_path = use_connection().location.pathname
6565

66-
@event(prevent_default=True)
6766
def on_click(_event: dict[str, Any]) -> None:
67+
if _event.get("ctrlKey", False):
68+
return
69+
6870
pathname, search = to.split("?", 1) if "?" in to else (to, "")
6971
if search:
7072
search = f"?{search}"

src/reactpy_router/static/link.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
document.querySelector(".UUID").addEventListener(
22
"click",
33
(event) => {
4-
let to = event.target.getAttribute("href");
5-
window.history.pushState({}, to, new URL(to, window.location));
4+
// Prevent default if ctrl isn't pressed
5+
if (!event.ctrlKey) {
6+
event.preventDefault();
7+
let to = event.target.getAttribute("href");
8+
window.history.pushState({}, to, new URL(to, window.location));
9+
}
610
},
711
{ once: true },
812
);

0 commit comments

Comments
 (0)