make all 4 type reports scroll in the same way
This commit is contained in:
parent
a8ee946d02
commit
88b5591066
|
|
@ -152,12 +152,22 @@ function ReportHtmlFrame({ html }: { html: string }) {
|
|||
const iframe = iframeRef.current;
|
||||
if (!iframe) return;
|
||||
|
||||
let resizeObserver: ResizeObserver | null = null;
|
||||
|
||||
const updateHeight = () => {
|
||||
try {
|
||||
const doc = iframe.contentDocument || iframe.contentWindow?.document;
|
||||
if (doc?.body) {
|
||||
const newHeight = doc.body.scrollHeight + 20;
|
||||
const newHeight = Math.max(doc.body.scrollHeight, doc.documentElement.scrollHeight) + 40;
|
||||
if (newHeight > 50) setHeight(newHeight);
|
||||
|
||||
if (!resizeObserver) {
|
||||
resizeObserver = new ResizeObserver(() => {
|
||||
const h = Math.max(doc.body.scrollHeight, doc.documentElement.scrollHeight) + 40;
|
||||
if (h > 50) setHeight(h);
|
||||
});
|
||||
resizeObserver.observe(doc.body);
|
||||
}
|
||||
}
|
||||
} catch { /* cross-origin safety */ }
|
||||
};
|
||||
|
|
@ -168,6 +178,7 @@ function ReportHtmlFrame({ html }: { html: string }) {
|
|||
return () => {
|
||||
iframe.removeEventListener('load', updateHeight);
|
||||
timers.forEach(clearTimeout);
|
||||
resizeObserver?.disconnect();
|
||||
};
|
||||
}, [html]);
|
||||
|
||||
|
|
@ -175,6 +186,7 @@ function ReportHtmlFrame({ html }: { html: string }) {
|
|||
<iframe
|
||||
ref={iframeRef}
|
||||
srcDoc={html}
|
||||
scrolling="no"
|
||||
style={{
|
||||
width: '100%',
|
||||
height,
|
||||
|
|
|
|||
Loading…
Reference in New Issue