fix web aux click on all browsers (#2633)

This commit is contained in:
Hailey 2024-02-06 09:00:16 -08:00 committed by GitHub
parent 2f1ce117d7
commit 065a094087
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 44 additions and 58 deletions

View file

@ -0,0 +1,30 @@
import React from 'react'
import {Platform} from 'react-native'
const onMouseUp = (e: React.MouseEvent & {target: HTMLElement}) => {
// Only handle whenever it is the middle button
if (e.button !== 1 || e.target.closest('a') || e.target.tagName === 'A') {
return
}
e.target.dispatchEvent(
new MouseEvent('click', {metaKey: true, bubbles: true}),
)
}
const onMouseDown = (e: React.MouseEvent) => {
// Prevents the middle click scroll from enabling
if (e.button !== 1) return
e.preventDefault()
}
export function WebAuxClickWrapper({children}: React.PropsWithChildren<{}>) {
if (Platform.OS !== 'web') return children
return (
// @ts-ignore web only
<div onMouseDown={onMouseDown} onMouseUp={onMouseUp}>
{children}
</div>
)
}