Skip to content

Commit 67dd7c2

Browse files
added forwardRef to py-inputbox
1 parent 65ff0d3 commit 67dd7c2

File tree

2 files changed

+29
-12
lines changed

2 files changed

+29
-12
lines changed

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

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

45
/**
56
* @param root0
67
* @param root0.children
78
* @deprecated
89
*/
9-
const PyInputBox: PyInputBoxTag = <T extends object>({
10-
children,
11-
...rest
12-
}: PyInputBoxProperties<T>): JSX.Element => {
13-
return <py-inputbox {...rest}>{children}</py-inputbox>;
14-
};
10+
const PyInputBox: PyInputBoxTag = forwardRef(
11+
<OptionalProperties extends object>(
12+
{ children, ...rest }: PyInputBoxProperties<OptionalProperties>,
13+
reference: ForwardedRef<HTMLElement> | undefined,
14+
// eslint-disable-next-line max-params
15+
): JSX.Element => {
16+
return (
17+
<py-inputbox ref={reference} {...rest}>
18+
{children}
19+
</py-inputbox>
20+
);
21+
},
22+
) as PyInputBoxTag;
23+
24+
PyInputBox.displayName = "PyInputBox";
1525

1626
PyInputBox.propTypes = {
1727
children: propTypes.string.isRequired,

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

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import type {
1+
import {
22
DetailedHTMLProps,
3+
ForwardedRef,
34
HTMLAttributes,
45
WeakValidationMap,
56
} from "react";
@@ -14,11 +15,17 @@ export type PyInputBoxPropertiesBase = Omit<
1415
children: string;
1516
};
1617

17-
export type PyInputBoxProperties<T> = T extends infer T
18-
? T & PyInputBoxPropertiesBase
19-
: PyInputBoxPropertiesBase;
18+
export type PyInputBoxProperties<OptionalProperties> =
19+
OptionalProperties extends infer OptionalProperties
20+
? OptionalProperties & PyInputBoxPropertiesBase
21+
: PyInputBoxPropertiesBase;
2022

2123
export type PyInputBoxTag = {
22-
<T extends object>(properties: PyInputBoxProperties<T>): JSX.Element;
23-
propTypes: WeakValidationMap<PyInputBoxPropertiesBase>;
24+
<OptionalProperties extends object>(
25+
properties: PyInputBoxProperties<OptionalProperties>,
26+
reference?: ForwardedRef<HTMLElement>,
27+
): JSX.Element;
28+
displayName?: string;
29+
defaultProps?: Partial<PyInputBoxPropertiesBase>;
30+
propTypes?: WeakValidationMap<PyInputBoxPropertiesBase>;
2431
};

0 commit comments

Comments
 (0)