Only handle "normal" clicks on <Link>s (#3056)

* Fixing https://github.com/yewstack/yew/issues/2911

Prevents Link onclick behaviour from executing if the Ctrl key (for
Windows and Linux) or Meta Key (For Mac) is pressed.

This technically introduces a bug that means that links will reload the
page on windows machines when the windows key is held down. However,
this error is also in React Router, so I think we can get away with it.

See:
11156ac7f3/packages/react-router-dom/dom.ts (L29)

* Router Links now use default browser behaviour for alt and shift keys.

This change is inspired by 11156ac7f3/packages/react-router-dom/dom.ts (L29)

This allows uses to shift click links to save whatever the link points
at, and alt click on links to open them in new windows
This commit is contained in:
Kai Salmon 2022-12-22 20:38:26 +00:00 committed by GitHub
parent aebd225963
commit 1542e2b181
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -55,8 +55,10 @@ where
let query = query.clone();
Callback::from(move |e: MouseEvent| {
if e.meta_key() || e.ctrl_key() || e.shift_key() || e.alt_key() {
return;
}
e.prevent_default();
match query {
None => {
navigator.push(&to);