From 8f8750e360f8a522b8f06c03450dba2b633d0ea0 Mon Sep 17 00:00:00 2001 From: Javier Pedemonte Date: Thu, 25 Jul 2024 11:30:02 -0500 Subject: [PATCH] fix: hide elements with no dimensions --- .../components/PdfViewer/PdfViewerTextLayer.tsx | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/packages/discovery-react-components/src/components/DocumentPreview/components/PdfViewer/PdfViewerTextLayer.tsx b/packages/discovery-react-components/src/components/DocumentPreview/components/PdfViewer/PdfViewerTextLayer.tsx index 8ca9d39f..e35dc28a 100644 --- a/packages/discovery-react-components/src/components/DocumentPreview/components/PdfViewer/PdfViewerTextLayer.tsx +++ b/packages/discovery-react-components/src/components/DocumentPreview/components/PdfViewer/PdfViewerTextLayer.tsx @@ -137,9 +137,14 @@ function adjustTextDivs( const expectedHeight = textItem.height * scale; const actualHeight = textDivElm.getBoundingClientRect().height; - /** - * Retrieve scale definition from within `transform` style rule - */ + // hide elements that don't have dimensions + if (expectedHeight === 0 || expectedWidth === 0) { + textDivElm.style.visibility = 'hidden'; + textDivElm.style.transform = ''; + continue; + } + + // retrieve scale definition from within `transform` style rule function getScale(element: HTMLElement, type: 'x' | 'y'): number | null { const pattern = type === 'x' ? scaleXPattern : scaleYPattern; const match = element.style.transform?.match(pattern);