Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ENG-1663] Prevent middle-click opening new tab #2168

Merged
merged 1 commit into from
Mar 6, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion interface/app/$libraryId/Layout/Sidebar/SidebarLayout/Link.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { cva } from 'class-variance-authority';
import clsx from 'clsx';
import { forwardRef, PropsWithChildren } from 'react';
import { forwardRef, PropsWithChildren, useEffect } from 'react';
import { NavLink, NavLinkProps } from 'react-router-dom';
import { useOperatingSystem } from '~/hooks/useOperatingSystem';
import { usePlatform } from '~/util/Platform';
Expand Down Expand Up @@ -31,6 +31,17 @@ const Link = forwardRef<
const os = useOperatingSystem();
const { platform } = usePlatform();

//prevents middle click from opening new tab
useEffect(() => {
const handleClick = (e: MouseEvent) => {
if (e.button === 1) e.preventDefault();
};
document.addEventListener('auxclick', handleClick);
return () => {
document.removeEventListener('auxclick', handleClick);
};
}, []);

return (
<NavLink
onClick={(e) => {
Expand Down
Loading