From 517f82b4b4017edb1c9e13b218256492139e3a91 Mon Sep 17 00:00:00 2001 From: Cesar Perez Date: Mon, 13 Nov 2023 09:08:54 -0700 Subject: [PATCH] added ability to forward refs in Bar and Path components --- packages/victory-bar/src/bar.js | 8 +++++--- .../victory-core/src/victory-primitives/path.tsx | 14 +++++++++----- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/packages/victory-bar/src/bar.js b/packages/victory-bar/src/bar.js index 631109739..ccc5e73cc 100644 --- a/packages/victory-bar/src/bar.js +++ b/packages/victory-bar/src/bar.js @@ -1,6 +1,6 @@ import { assign } from "lodash"; import PropTypes from "prop-types"; -import React from "react"; +import React, { forwardRef } from "react"; import { CommonProps, Helpers, Path } from "victory-core"; import { getStyle, getBarWidth, getCornerRadius } from "./bar-helper-methods"; import { getPolarBarPath, getBarPath } from "./path-helper-methods"; @@ -41,7 +41,8 @@ const evaluateProps = (props) => { }); }; -const Bar = (props) => { +// eslint-disable-next-line prefer-arrow-callback +const Bar = forwardRef(function Bar(props, ref) { props = evaluateProps(props); const { polar, origin, style, barWidth, cornerRadius } = props; @@ -63,8 +64,9 @@ const Bar = (props) => { shapeRendering: props.shapeRendering, transform: props.transform || defaultTransform, tabIndex: props.tabIndex, + ref, }); -}; +}); Bar.propTypes = { ...CommonProps.primitiveProps, diff --git a/packages/victory-core/src/victory-primitives/path.tsx b/packages/victory-core/src/victory-primitives/path.tsx index 129ff76b0..c32f7aa13 100644 --- a/packages/victory-core/src/victory-primitives/path.tsx +++ b/packages/victory-core/src/victory-primitives/path.tsx @@ -1,16 +1,20 @@ -import React from "react"; +import React, { forwardRef } from "react"; import { VictoryPrimitiveShapeProps } from "./types"; -export const Path = (props: VictoryPrimitiveShapeProps) => { +// eslint-disable-next-line prefer-arrow-callback +export const Path = forwardRef(function Path( + props: VictoryPrimitiveShapeProps, + ref, +) { // eslint-disable-next-line react/prop-types const { desc, ...rest } = props; return desc ? ( // @ts-expect-error FIXME: "id cannot be a number" - + {desc} ) : ( // @ts-expect-error FIXME: "id cannot be a number" - + ); -}; +});