Skip to content

Commit 9afbe4a

Browse files
added forwardRef to py-box
1 parent 6925f40 commit 9afbe4a

File tree

2 files changed

+25
-8
lines changed

2 files changed

+25
-8
lines changed

source/library/components/py-box/py-box.tsx

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import propTypes from "prop-types";
2+
import { forwardRef, type ForwardedRef } from "react";
23
import type { PyBoxProperties, PyBoxTag } from "./py-box.types";
34

45
/**
@@ -7,12 +8,21 @@ import type { PyBoxProperties, PyBoxTag } from "./py-box.types";
78
* @param root0.children
89
* @deprecated
910
*/
10-
const PyBox: PyBoxTag = <T extends object>({
11-
children,
12-
...rest
13-
}: PyBoxProperties<T>): JSX.Element => {
14-
return <py-box {...rest}>{children}</py-box>;
15-
};
11+
const PyBox: PyBoxTag = forwardRef(
12+
<T extends object>(
13+
{ children, ...rest }: PyBoxProperties<T>,
14+
reference: ForwardedRef<HTMLElement> | undefined,
15+
// eslint-disable-next-line max-params
16+
): JSX.Element => {
17+
return (
18+
<py-box ref={reference} {...rest}>
19+
{children}
20+
</py-box>
21+
);
22+
},
23+
) as PyBoxTag;
24+
25+
PyBox.displayName = "PyBox";
1626

1727
PyBox.propTypes = {
1828
children: propTypes.oneOfType([

source/library/components/py-box/py-box.types.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import type {
22
DetailedHTMLProps,
33
HTMLAttributes,
4+
LegacyRef,
45
PropsWithChildren,
56
WeakValidationMap,
67
} from "react";
8+
79
import type ReactElementProps from "~types/react-element-properties/react-element-properties";
810

911
export type PyBoxPropertiesBase = PropsWithChildren<
@@ -19,6 +21,11 @@ export type PyBoxProperties<T> = T extends infer T
1921
: PyBoxPropertiesBase;
2022

2123
export type PyBoxTag = {
22-
<T extends object>(properties: PyBoxProperties<T>): JSX.Element;
23-
propTypes: WeakValidationMap<PyBoxPropertiesBase>;
24+
<T extends object>(
25+
properties: PyBoxProperties<T>,
26+
reference: LegacyRef<HTMLElement> | undefined,
27+
): JSX.Element;
28+
displayName?: string;
29+
defaultProps?: Partial<PyBoxPropertiesBase>;
30+
propTypes?: WeakValidationMap<PyBoxPropertiesBase>;
2431
};

0 commit comments

Comments
 (0)