Skip to content

Commit 1876b7a

Browse files
added forwardRef to py-register-widget
1 parent fd223cc commit 1876b7a

File tree

2 files changed

+38
-15
lines changed

2 files changed

+38
-15
lines changed

source/library/components/py-register-widget/py-register-widget.tsx

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import propTypes from "prop-types";
2+
import { forwardRef, type ForwardedRef } from "react";
3+
24
import type {
35
PyRegisterWidgetProperties,
46
PyRegisterWidgetTag,
@@ -11,16 +13,30 @@ import type {
1113
* @param root0.pythonClass
1214
* @deprecated
1315
*/
14-
const PyRegisterWidget: PyRegisterWidgetTag = <T extends object>({
15-
name,
16-
src,
17-
pythonClass,
18-
...rest
19-
}: PyRegisterWidgetProperties<T>): JSX.Element => {
20-
return (
21-
<py-register-widget {...rest} src={src} name={name} klass={pythonClass} />
22-
);
23-
};
16+
const PyRegisterWidget: PyRegisterWidgetTag = forwardRef(
17+
<OptionalProperties extends object>(
18+
{
19+
name,
20+
src,
21+
pythonClass,
22+
...rest
23+
}: PyRegisterWidgetProperties<OptionalProperties>,
24+
reference: ForwardedRef<HTMLElement> | undefined,
25+
// eslint-disable-next-line max-params
26+
): JSX.Element => {
27+
return (
28+
<py-register-widget
29+
ref={reference}
30+
{...rest}
31+
src={src}
32+
name={name}
33+
klass={pythonClass}
34+
/>
35+
);
36+
},
37+
) as PyRegisterWidgetTag;
38+
39+
PyRegisterWidget.displayName = "PyRegisterWidget";
2440

2541
PyRegisterWidget.propTypes = {
2642
name: propTypes.string,

source/library/components/py-register-widget/py-register-widget.types.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type {
22
DetailedHTMLProps,
3+
ForwardedRef,
34
HTMLAttributes,
45
WeakValidationMap,
56
} from "react";
@@ -16,11 +17,17 @@ export type PyRegisterWidgetPropertiesBase = Omit<
1617
pythonClass?: string;
1718
};
1819

19-
export type PyRegisterWidgetProperties<T> = T extends infer T
20-
? T & PyRegisterWidgetPropertiesBase
21-
: PyRegisterWidgetPropertiesBase;
20+
export type PyRegisterWidgetProperties<OptionalProperties> =
21+
OptionalProperties extends infer OptionalProperties
22+
? OptionalProperties & PyRegisterWidgetPropertiesBase
23+
: PyRegisterWidgetPropertiesBase;
2224

2325
export type PyRegisterWidgetTag = {
24-
<T extends object>(properties: PyRegisterWidgetProperties<T>): JSX.Element;
25-
propTypes: WeakValidationMap<PyRegisterWidgetPropertiesBase>;
26+
<OptionalProperties extends object>(
27+
properties: PyRegisterWidgetProperties<OptionalProperties>,
28+
reference?: ForwardedRef<HTMLElement>,
29+
): JSX.Element;
30+
displayName?: string;
31+
defaultProps?: Partial<PyRegisterWidgetPropertiesBase>;
32+
propTypes?: WeakValidationMap<PyRegisterWidgetPropertiesBase>;
2633
};

0 commit comments

Comments
 (0)