Skip to content

Commit

Permalink
[ENG-1663] Prevent middle-click opening new tab (#2168)
Browse files Browse the repository at this point in the history
Update Link.tsx
  • Loading branch information
ameer2468 committed Mar 6, 2024
1 parent c11ecd2 commit 55d2ec7
Showing 1 changed file with 12 additions and 1 deletion.
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

0 comments on commit 55d2ec7

Please sign in to comment.