Skip to content

Commit 03449e5

Browse files
(Radio): pass id explicitly to make label work fine
1 parent 94eae60 commit 03449e5

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/scripts/Radio.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { FC, InputHTMLAttributes, Ref, useContext } from 'react';
1+
import React, { FC, InputHTMLAttributes, Ref, useId, useContext } from 'react';
22
import classnames from 'classnames';
33
import { RadioGroupContext, RadioValueType } from './RadioGroup';
44
import { useEventCallback } from './hooks';
@@ -17,7 +17,7 @@ export type RadioProps = {
1717
*
1818
*/
1919
export const Radio: FC<RadioProps> = ({
20-
id,
20+
id: id_,
2121
className,
2222
label,
2323
name,
@@ -33,6 +33,10 @@ export const Radio: FC<RadioProps> = ({
3333
errorId,
3434
onValueChange,
3535
} = useContext(RadioGroupContext);
36+
37+
const prefix = useId();
38+
const id = id_ ?? `${prefix}-id`;
39+
3640
const onChange = useEventCallback(
3741
(e: React.ChangeEvent<HTMLInputElement>) => {
3842
onChange_?.(e);

0 commit comments

Comments
 (0)