Unverified Commit 052a9d23 authored by Yuhei Yasuda's avatar Yuhei Yasuda Committed by GitHub

Don’t prevent the browser’s default behavior for Alt key (#16003)

In most browsers, clicking links with the Alt key has a special behavior, for example, Chrome downloads the target resource. As with other modifier keys, the router should stop the original navigation to avoid preventing the browser’s default behavior.

When users click a link while holding the Alt key together, the browsers behave as follows.

Windows 10:

| Browser    | Behavior                                    |
|:-----------|:--------------------------------------------|
| Chrome 84  | Download the target resource                |
| Firefox 79 | Prevent navigation and therefore do nothing |
| Edge 84    | Download the target resource                |
| IE 11      | No impact                                   |

macOS Catalina:

| Browser    | Behavior                                    |
|:-----------|:--------------------------------------------|
| Chrome 84  | Download the target resource                |
| Firefox 79 | Prevent navigation and therefore do nothing |
| Safari 13  | Download the target resource                |
parent 378f092a
......@@ -97,13 +97,14 @@ function prefetch(
prefetched[href + '%' + as] = true
}
function isNewTabRequest(event: React.MouseEvent) {
function isModifiedEvent(event: React.MouseEvent) {
const { target } = event.currentTarget as HTMLAnchorElement
return (
(target && target !== '_self') ||
event.metaKey ||
event.ctrlKey ||
event.shiftKey ||
event.altKey || // triggers resource download
(event.nativeEvent && event.nativeEvent.which === 2)
)
}
......@@ -119,8 +120,8 @@ function linkClicked(
): void {
const { nodeName } = e.currentTarget
if (nodeName === 'A' && (isNewTabRequest(e) || !isLocalURL(href))) {
// ignore click for new tab / new window behavior
if (nodeName === 'A' && (isModifiedEvent(e) || !isLocalURL(href))) {
// ignore click for browser’s default behavior
return
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment