react-pdf-viewer icon indicating copy to clipboard operation
react-pdf-viewer copied to clipboard

zero max-height issue with toolbar popover menus

Open joao-arau-symphony opened this issue 2 years ago • 4 comments

In our application all pop-over menus look like this : Screenshot from 2023-09-19 09-54-21

The code we are using looks like this:


const renderToolbar = getRenderToolbar(isMobile);
	const defaultLayoutPluginInstance = defaultLayoutPlugin({
		sidebarTabs: () => [],
                renderToolbar,
	});

[...]

<div style={{ height: '500px', width: '100%' }}>
					{/* @ts-ignore */}
					<Viewer fileUrl={file} plugins={[defaultLayoutPluginInstance]} />
				</div>

This problem happens with and without using a custom toolbar. When investigating we found this problem with the max-height of the element. After manually disabling this value in chrome dev tools evrything shows correctly.

Screenshot from 2023-09-19 09-17-30

The webapp is built with create-react-app (react-scripts version "5.0.1")

joao-arau-symphony avatar Sep 19 '23 13:09 joao-arau-symphony

@joao-arau-symphony , Please check the CSS of your parent components where your pdf-viewer has been embedded. mostly because of position : absolute or some other position property in your components you might face this issue.

AchyuthRampalli avatar Oct 11 '23 06:10 AchyuthRampalli

I have the same issue with 3.12.0 and I don't have any weird CSS, just using Material UI 5

sereyn avatar Dec 13 '23 13:12 sereyn

@phuocng I believe the issue is here: https://github.com/react-pdf-viewer/react-pdf-viewer/blob/da204fec47b326bfe88ea2a4451511db1a531fdb/packages/core/src/portal/PopoverBody.tsx#L46C61-L46C61 document.body.clientHeight here gives value of zero. It should be probably window.innerHeight perhaps 🤔 . Should be a quick one line fix 🤞

Temporary solution in react for other folks:

useEffect(() => {
    // Function to modify the style of popovers
    const modifyPopoversStyle = () => {
      // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
      const popovers = document.querySelectorAll(
        '[id^="rpv-core__popover-body-inner"]',
      ) as NodeListOf<HTMLElement>;
      popovers.forEach((popover) => {
        if (popover.style.maxHeight === "0px") {
          popover.style.maxHeight = "none"; // Unset the max-height
        }
      });
    };

    // Create a new MutationObserver instance
    const observer = new MutationObserver((mutations) => {
      mutations.forEach((mutation) => {
        if (mutation.addedNodes.length) {
          modifyPopoversStyle();
        }
      });
    });

    // Start observing the document body for added nodes
    observer.observe(document.body, { childList: true, subtree: true });

    // Cleanup function
    return () => observer.disconnect();
  }, []);

abhimskywalker avatar Dec 28 '23 15:12 abhimskywalker

I also have this issue, not only for the more actions button in the right corner, but as well as for the search button on the far left, which practically makes those functions render obsolete.. Any updates on this? We're using @react-pdf-viewer/core": "^3.12.0", "@react-pdf-viewer/default-layout": "^3.12.0"

Ljupcho-Petrushevski avatar Aug 07 '24 09:08 Ljupcho-Petrushevski