diff options
Diffstat (limited to 'src/view')
-rw-r--r-- | src/view/com/util/Link.tsx | 25 | ||||
-rw-r--r-- | src/view/com/util/WebAuxClickWrapper.tsx | 30 | ||||
-rw-r--r-- | src/view/shell/index.web.tsx | 2 |
3 files changed, 44 insertions, 13 deletions
diff --git a/src/view/com/util/Link.tsx b/src/view/com/util/Link.tsx index a517ba430..afbdeb8f4 100644 --- a/src/view/com/util/Link.tsx +++ b/src/view/com/util/Link.tsx @@ -31,6 +31,7 @@ import {PressableWithHover} from './PressableWithHover' import FixedTouchableHighlight from '../pager/FixedTouchableHighlight' import {useModalControls} from '#/state/modals' import {useOpenLink} from '#/state/preferences/in-app-browser' +import {WebAuxClickWrapper} from 'view/com/util/WebAuxClickWrapper' type Event = | React.MouseEvent<HTMLAnchorElement, MouseEvent> @@ -104,17 +105,19 @@ export const Link = memo(function Link({ ) } return ( - <TouchableWithoutFeedback - testID={testID} - onPress={onPress} - accessible={accessible} - accessibilityRole="link" - {...props}> - {/* @ts-ignore web only -prf */} - <View style={style} href={anchorHref}> - {children ? children : <Text>{title || 'link'}</Text>} - </View> - </TouchableWithoutFeedback> + <WebAuxClickWrapper> + <TouchableWithoutFeedback + testID={testID} + onPress={onPress} + accessible={accessible} + accessibilityRole="link" + {...props}> + {/* @ts-ignore web only -prf */} + <View style={style} href={anchorHref}> + {children ? children : <Text>{title || 'link'}</Text>} + </View> + </TouchableWithoutFeedback> + </WebAuxClickWrapper> ) } 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> + ) +} diff --git a/src/view/shell/index.web.tsx b/src/view/shell/index.web.tsx index 76f4f5c9b..97c065502 100644 --- a/src/view/shell/index.web.tsx +++ b/src/view/shell/index.web.tsx @@ -11,7 +11,6 @@ import {DrawerContent} from './Drawer' import {useWebMediaQueries} from '../../lib/hooks/useWebMediaQueries' import {useNavigation} from '@react-navigation/native' import {NavigationProp} from 'lib/routes/types' -import {useAuxClick} from 'lib/hooks/useAuxClick' import {t} from '@lingui/macro' import {useIsDrawerOpen, useSetDrawerOpen} from '#/state/shell' import {useCloseAllActiveElements} from '#/state/util' @@ -26,7 +25,6 @@ function ShellInner() { const closeAllActiveElements = useCloseAllActiveElements() useWebBodyScrollLock(isDrawerOpen) - useAuxClick() useEffect(() => { const unsubscribe = navigator.addListener('state', () => { |