Skip to content

Commit

Permalink
Fix SVG download button by properly propagating ref (#413)
Browse files Browse the repository at this point in the history
  • Loading branch information
louwenjjr authored Jul 19, 2024
1 parent 22467fe commit 4c7f3f7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
8 changes: 4 additions & 4 deletions packages/sections/src/target/Expression/GtexVariability.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useRef, useEffect } from "react";
import { useRef, useEffect, forwardRef } from "react";
import {
scaleLinear,
scalePoint,
Expand Down Expand Up @@ -48,7 +48,7 @@ function buildTooltip(X, tooltipObject, data) {
.join("");
}

function GtexVariability({ data }) {
const GtexVariability = forwardRef(function GtexVariability({ data }, ref) {
const theme = useTheme();
const boxPlotRef = useRef();
const tooltipRef = useRef();
Expand Down Expand Up @@ -239,7 +239,7 @@ function GtexVariability({ data }) {
}

return (
<svg xmlns="http://www.w3.org/2000/svg" height={height} width={width}>
<svg xmlns="http://www.w3.org/2000/svg" height={height} width={width} ref={ref}>
<text x={margin.left} y="15" fill={theme.palette.grey[700]} fontSize="14">
Normalised expression (RPKM)
</text>
Expand All @@ -253,6 +253,6 @@ function GtexVariability({ data }) {
<g ref={tooltipRef} transform={`translate(${margin.left}, ${margin.top})`} />
</svg>
);
}
});

export default GtexVariability;
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import downloadSvg from "./DownloadSvg";
import PlotContainer from "../PlotContainer";

const handleSvgDownload = (svgContainer, filenameStem) => {
const node = svgContainer;
const svgNode = node.nodeName === "svg" ? node : node.querySelector("svg");
const svgNode = svgContainer.current;
if (svgNode === null) return;
downloadSvg({ svgNode, filenameStem });
};

Expand Down Expand Up @@ -34,7 +34,7 @@ function DownloadSvgPlot({
if (reportDownloadEvent) {
reportDownloadEvent();
}
handleSvgDownload(svgContainer.current, filenameStem);
handleSvgDownload(svgContainer, filenameStem);
}}
>
SVG
Expand Down

0 comments on commit 4c7f3f7

Please sign in to comment.