Skip to content

Build your personal knowledge base with Trilium Notes

fix(client/pdf): not always focusing on click

Elian Dorane161ffce57b6
diff --git a/apps/client/src/widgets/type_widgets/file/Pdf.tsx b/apps/client/src/widgets/type_widgets/file/Pdf.tsx
index c915a0a5d4..6c1512d87d 100644
--- a/apps/client/src/widgets/type_widgets/file/Pdf.tsx
+++ b/apps/client/src/widgets/type_widgets/file/Pdf.tsx
@@ -151,25 +151,6 @@ export default function PdfPreview({ note, blob, componentId, noteContext }: {
}
}, [ blob ]);
- // Trigger focus when iframe content is clicked (iframe focus doesn't bubble)
- useEffect(() => {
- const iframe = iframeRef.current;
- if (!iframe) return;
-
- const handleIframeClick = () => {
- if (noteContext.ntxId) {
- appContext.tabManager.activateNoteContext(noteContext.ntxId);
- }
- };
-
- // Listen for clicks on the iframe's content window
- const iframeDoc = iframe.contentWindow?.document;
- if (iframeDoc) {
- iframeDoc.addEventListener('click', handleIframeClick);
- return () => iframeDoc.removeEventListener('click', handleIframeClick);
- }
- }, [ iframeRef.current?.contentWindow, noteContext ]);
-
return (historyConfig &&
<iframe
tabIndex={300}
@@ -182,6 +163,12 @@ export default function PdfPreview({ note, blob, componentId, noteContext }: {
win.TRILIUM_VIEW_HISTORY_STORE = historyConfig.config;
}
onLoad();
+
+ if (iframeRef.current?.contentWindow) {
+ iframeRef.current.contentWindow.addEventListener('click', () => {
+ appContext.tabManager.activateNoteContext(noteContext.ntxId);
+ });
+ }
}}
/>
);