fix(html): prevent image diff from flickering (#11184)

This commit is contained in:
Pavel Feldman 2022-01-06 15:19:16 -08:00 committed by GitHub
parent e1772f15b5
commit 16dafba153
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -122,16 +122,23 @@ const ImageDiff: React.FunctionComponent<{
diff?: TestAttachment, diff?: TestAttachment,
}> = ({ actual, expected, diff }) => { }> = ({ actual, expected, diff }) => {
const [selectedTab, setSelectedTab] = React.useState<string>('actual'); const [selectedTab, setSelectedTab] = React.useState<string>('actual');
const diffElement = React.useRef<HTMLImageElement>(null);
const tabs = []; const tabs = [];
tabs.push({ tabs.push({
id: 'actual', id: 'actual',
title: 'Actual', title: 'Actual',
render: () => <img src={actual.path}/> render: () => <img src={actual.path} onLoad={() => {
if (diffElement.current)
diffElement.current.style.minHeight = diffElement.current.offsetHeight + 'px';
}}/>
}); });
tabs.push({ tabs.push({
id: 'expected', id: 'expected',
title: 'Expected', title: 'Expected',
render: () => <img src={expected.path}/> render: () => <img src={expected.path} onLoad={() => {
if (diffElement.current)
diffElement.current.style.minHeight = diffElement.current.offsetHeight + 'px';
}}/>
}); });
if (diff) { if (diff) {
tabs.push({ tabs.push({
@ -140,7 +147,7 @@ const ImageDiff: React.FunctionComponent<{
render: () => <img src={diff.path}/> render: () => <img src={diff.path}/>
}); });
} }
return <div className='vbox' data-testid='test-result-image-mismatch'> return <div className='vbox' data-testid='test-result-image-mismatch' ref={diffElement}>
<TabbedPane tabs={tabs} selectedTab={selectedTab} setSelectedTab={setSelectedTab} /> <TabbedPane tabs={tabs} selectedTab={selectedTab} setSelectedTab={setSelectedTab} />
</div>; </div>;
}; };