diff options
author | Hailey <me@haileyok.com> | 2024-02-06 09:00:16 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-02-06 09:00:16 -0800 |
commit | 065a09408767a870c48c99549cc0198955ea1ccf (patch) | |
tree | 65474dcd1dade94870b7318dbc27004ea0b53835 /src/view/com/util/WebAuxClickWrapper.tsx | |
parent | 2f1ce117d7db8db168303f6064e69024e920585e (diff) | |
download | voidsky-065a09408767a870c48c99549cc0198955ea1ccf.tar.zst |
fix web aux click on all browsers (#2633)
Diffstat (limited to 'src/view/com/util/WebAuxClickWrapper.tsx')
-rw-r--r-- | src/view/com/util/WebAuxClickWrapper.tsx | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/src/view/com/util/WebAuxClickWrapper.tsx b/src/view/com/util/WebAuxClickWrapper.tsx new file mode 100644 index 000000000..8105a8518 --- /dev/null +++ b/src/view/com/util/WebAuxClickWrapper.tsx @@ -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> + ) +} |