Papermark is the open-source DocSend alternative and secure data rooms with built-in analytics and custom domains.
Fix: Prevent event propagation in preview buttons
Cursor Agent00704135015c
diff --git a/components/documents/document-preview-button.tsx b/components/documents/document-preview-button.tsxindex c60d310f..77179f62 100644--- a/components/documents/document-preview-button.tsx+++ b/components/documents/document-preview-button.tsx@@ -61,6 +61,11 @@ export function DocumentPreviewButton({setIsPreviewOpen(true);};+ // Stop propagation on the container to prevent parent click handlers from firing+ const handleContainerClick = (e: React.MouseEvent<HTMLDivElement>) => {+ e.stopPropagation();+ };+const button = (<Buttonvariant={variant}@@ -93,14 +98,14 @@ export function DocumentPreviewButton({);return (- <>+ <div onClick={handleContainerClick} onMouseDown={handleContainerClick}>{wrappedButton}<DocumentPreviewModaldocumentId={documentId}isOpen={isPreviewOpen}onClose={() => setIsPreviewOpen(false)}/>- </>+ </div>);}diff --git a/components/links/preview-button.tsx b/components/links/preview-button.tsxindex 0da03f84..ac04101a 100644--- a/components/links/preview-button.tsx+++ b/components/links/preview-button.tsx@@ -15,8 +15,18 @@ const PreviewButton = ({isProcessing: boolean;onPreview: (link: LinkWithViews) => void;}) => {+ const handleClick = (e: React.MouseEvent) => {+ e.stopPropagation();+ e.preventDefault();+ onPreview(link);+ };++ const handleContainerClick = (e: React.MouseEvent) => {+ e.stopPropagation();+ };+return (- <div className="relative">+ <div className="relative" onClick={handleContainerClick} onMouseDown={handleContainerClick}><ButtonTooltipcontent={isProcessing ? "Preparing preview" : "Preview link"}>@@ -25,7 +35,7 @@ const PreviewButton = ({variant={"link"}size={"icon"}className="group h-7 w-8"- onClick={() => onPreview(link)}+ onClick={handleClick}disabled={isProcessing}><span className="sr-only">Preview link</span>