Skip to content

Commit

Permalink
added ability to forward refs in Bar and Path components
Browse files Browse the repository at this point in the history
  • Loading branch information
Cesar Perez committed Nov 13, 2023
1 parent 0a26400 commit 517f82b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
8 changes: 5 additions & 3 deletions packages/victory-bar/src/bar.js
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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;

Expand All @@ -63,8 +64,9 @@ const Bar = (props) => {
shapeRendering: props.shapeRendering,
transform: props.transform || defaultTransform,
tabIndex: props.tabIndex,
ref,
});
};
});

Bar.propTypes = {
...CommonProps.primitiveProps,
Expand Down
14 changes: 9 additions & 5 deletions packages/victory-core/src/victory-primitives/path.tsx
Original file line number Diff line number Diff line change
@@ -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"
<path {...rest}>
<path {...rest} ref={ref}>
<desc>{desc}</desc>
</path>
) : (
// @ts-expect-error FIXME: "id cannot be a number"
<path {...rest} />
<path {...rest} ref={ref} />
);
};
});

0 comments on commit 517f82b

Please sign in to comment.