@@ -109,7 +109,7 @@ export const CheckboxWithLabel = React.forwardRef<HTMLInputElement, CheckboxProp
109109 } , [ defaultChecked ] ) ;
110110
111111 return (
112- < div
112+ < label
113113 className = { cn (
114114 "group flex items-start gap-x-2 transition " ,
115115 props . readOnly || disabled ? "cursor-default" : "cursor-pointer" ,
@@ -118,11 +118,6 @@ export const CheckboxWithLabel = React.forwardRef<HTMLInputElement, CheckboxProp
118118 ( isDisabled || props . readOnly ) && isDisabledClassName ,
119119 className
120120 ) }
121- onClick = { ( e ) => {
122- //returning false is not setting the state to false, it stops the event from bubbling up
123- if ( isDisabled || props . readOnly === true ) return false ;
124- setIsChecked ( ( c ) => ! c ) ;
125- } }
126121 >
127122 < input
128123 { ...props }
@@ -131,9 +126,8 @@ export const CheckboxWithLabel = React.forwardRef<HTMLInputElement, CheckboxProp
131126 value = { value }
132127 checked = { isChecked }
133128 onChange = { ( e ) => {
134- //returning false is not setting the state to false, it stops the event from bubbling up
135- if ( isDisabled || props . readOnly === true ) return false ;
136- setIsChecked ( ! isChecked ) ;
129+ if ( isDisabled || props . readOnly === true ) return ;
130+ setIsChecked ( e . target . checked ) ;
137131 } }
138132 disabled = { isDisabled }
139133 className = { cn (
@@ -150,17 +144,15 @@ export const CheckboxWithLabel = React.forwardRef<HTMLInputElement, CheckboxProp
150144 />
151145 < div >
152146 < div className = "flex items-center gap-x-2" >
153- < label
154- htmlFor = { id }
147+ < span
155148 className = { cn (
156149 props . readOnly || disabled ? "cursor-default" : "cursor-pointer" ,
157150 labelClassName ,
158151 externalLabelClassName
159152 ) }
160- onClick = { ( e ) => e . preventDefault ( ) }
161153 >
162154 { label }
163- </ label >
155+ </ span >
164156 { badges && (
165157 < span className = "-mr-2 flex gap-x-1.5" >
166158 { badges . map ( ( badge ) => (
@@ -175,7 +167,7 @@ export const CheckboxWithLabel = React.forwardRef<HTMLInputElement, CheckboxProp
175167 </ Paragraph >
176168 ) }
177169 </ div >
178- </ div >
170+ </ label >
179171 ) ;
180172 }
181173) ;
0 commit comments