mirror of https://git.lenooby09.tech/LeNooby09/social-app.git
1import React from 'react' 2import {Platform} from 'react-native' 3 4const onMouseUp = (e: React.MouseEvent & {target: HTMLElement}) => { 5 // Only handle whenever it is the middle button 6 if (e.button !== 1 || e.target.closest('a') || e.target.tagName === 'A') { 7 return 8 } 9 10 e.target.dispatchEvent( 11 new MouseEvent('click', {metaKey: true, bubbles: true}), 12 ) 13} 14 15const onMouseDown = (e: React.MouseEvent) => { 16 // Prevents the middle click scroll from enabling 17 if (e.button !== 1) return 18 e.preventDefault() 19} 20 21export function WebAuxClickWrapper({children}: React.PropsWithChildren<{}>) { 22 if (Platform.OS !== 'web') return children 23 24 return ( 25 // @ts-ignore web only 26 <div onMouseDown={onMouseDown} onMouseUp={onMouseUp}> 27 {children} 28 </div> 29 ) 30}