Skip to content

Commit 04a0cac

Browse files
Added ref support in Radio.Item
1 parent 87678a7 commit 04a0cac

1 file changed

Lines changed: 36 additions & 31 deletions

File tree

src/components/Radio/Item.jsx

Lines changed: 36 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React from "react";
1+
import React, { forwardRef } from "react";
22

33
import classnames from "classnames";
44
import PropTypes from "prop-types";
@@ -7,37 +7,42 @@ import Label from "components/Label";
77
import { useId } from "hooks";
88
import { hyphenize } from "utils";
99

10-
const Item = ({
11-
name = "",
12-
label = "",
13-
className = "",
14-
labelProps,
15-
dataCy = "",
16-
...otherProps
17-
}) => {
18-
const id = useId(otherProps.id);
10+
const Item = forwardRef(
11+
(
12+
{
13+
name = "",
14+
label = "",
15+
className = "",
16+
labelProps,
17+
dataCy = "",
18+
...otherProps
19+
},
20+
ref
21+
) => {
22+
const id = useId(otherProps.id);
1923

20-
return (
21-
<div className={classnames(["neeto-ui-radio__item", className])}>
22-
<input
23-
{...{ id, name }}
24-
className="neeto-ui-radio"
25-
data-cy={dataCy || `${hyphenize(label)}-radio-input`}
26-
type="radio"
27-
{...otherProps}
28-
/>
29-
{label && (
30-
<Label
31-
data-cy={dataCy || `${hyphenize(label)}-radio-label`}
32-
htmlFor={id}
33-
{...labelProps}
34-
>
35-
{label}
36-
</Label>
37-
)}
38-
</div>
39-
);
40-
};
24+
return (
25+
<div className={classnames(["neeto-ui-radio__item", className])}>
26+
<input
27+
{...{ id, name, ref }}
28+
className="neeto-ui-radio"
29+
data-cy={dataCy || `${hyphenize(label)}-radio-input`}
30+
type="radio"
31+
{...otherProps}
32+
/>
33+
{label && (
34+
<Label
35+
data-cy={dataCy || `${hyphenize(label)}-radio-label`}
36+
htmlFor={id}
37+
{...labelProps}
38+
>
39+
{label}
40+
</Label>
41+
)}
42+
</div>
43+
);
44+
}
45+
);
4146

4247
Item.displayName = "Radio.Item";
4348

0 commit comments

Comments
 (0)