Skip to content

Commit ca894ab

Browse files
committed
Restore command + click behavior on Inertia links in React
In #1910 (d53b2b3), we switched to passing `event.nativeEvent` to `shouldIntercept` in an attempt to consistently always pass native browser events to this framework-agnostic helper. This actually introduced a bug though, because `currentTarget` is _different_ on React's synthetic event vs. the underlying native event. The correct value for `currentTarget` lives on the synthetic event. Since we are no longer relying on `event.which` (and this is the only property we used to be concerned with that was not included on the React synthetic event), we'll simply move back to passing the React synthetic event to `shouldIntercept`.
1 parent 2d4d4f4 commit ca894ab

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

packages/core/src/shouldIntercept.ts

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
1-
export default function shouldIntercept(event: MouseEvent | KeyboardEvent): boolean {
1+
// The actual event passed to this function could be a native JavaScript event
2+
// or a React synthetic event, so we are picking just the keys needed here (that
3+
// are present in both types).
4+
5+
export default function shouldIntercept(
6+
event: Pick<
7+
MouseEvent,
8+
'altKey' | 'ctrlKey' | 'defaultPrevented' | 'target' | 'currentTarget' | 'metaKey' | 'shiftKey' | 'button'
9+
>,
10+
): boolean {
211
const isLink = (event.currentTarget as HTMLElement).tagName.toLowerCase() === 'a'
312
return !(
413
(event.target && (event?.target as HTMLElement).isContentEditable) ||

packages/react/src/Link.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ const Link = forwardRef<unknown, InertiaLinkProps>(
7070
(event: React.MouseEvent) => {
7171
onClick(event)
7272

73-
if (shouldIntercept(event.nativeEvent)) {
73+
if (shouldIntercept(event)) {
7474
event.preventDefault()
7575

7676
router.visit(href, {

0 commit comments

Comments
 (0)