Skip to content

Commit 3a49bac

Browse files
(Checkbox): pass id surely to make label work fine
1 parent a27887e commit 3a49bac

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/scripts/Checkbox.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import React, {
22
FC,
33
InputHTMLAttributes,
44
Ref,
5+
useId,
56
useContext,
67
ReactNode,
78
} from 'react';
@@ -32,7 +33,7 @@ export type CheckboxProps = {
3233
export const Checkbox: FC<CheckboxProps> = (props) => {
3334
const {
3435
type, // eslint-disable-line @typescript-eslint/no-unused-vars
35-
id,
36+
id: id_,
3637
className,
3738
label,
3839
required,
@@ -45,6 +46,9 @@ export const Checkbox: FC<CheckboxProps> = (props) => {
4546
...rprops
4647
} = props;
4748

49+
const prefix = useId();
50+
const id = id_ ?? `${prefix}-id`;
51+
4852
const { grouped, error, errorId } = useContext(CheckboxGroupContext);
4953
const formElemProps = {
5054
required,

0 commit comments

Comments
 (0)