fix web aux click on all browsers (#2633)
This commit is contained in:
parent
2f1ce117d7
commit
065a094087
5 changed files with 44 additions and 58 deletions
30
src/view/com/util/WebAuxClickWrapper.tsx
Normal file
30
src/view/com/util/WebAuxClickWrapper.tsx
Normal 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>
|
||||
)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue