diff --git a/.oxlintrc.json b/.oxlintrc.json index 37048cb417..7c01c520b7 100644 --- a/.oxlintrc.json +++ b/.oxlintrc.json @@ -86,7 +86,7 @@ ], "jsx-a11y/label-has-associated-control": "error", "jsx-a11y/no-autofocus": "off", - "jsx-a11y/no-noninteractive-element-interactions": "off", + "jsx-a11y/no-noninteractive-element-interactions": "error", "jsx-a11y/no-static-element-interactions": "off", "jsx-a11y/prefer-tag-over-role": "off", "jsx-a11y/anchor-ambiguous-text": "error", diff --git a/apps/webapp/app/components/primitives/Checkbox.tsx b/apps/webapp/app/components/primitives/Checkbox.tsx index da63e2ed99..8db6defb4a 100644 --- a/apps/webapp/app/components/primitives/Checkbox.tsx +++ b/apps/webapp/app/components/primitives/Checkbox.tsx @@ -86,6 +86,12 @@ export const CheckboxWithLabel = React.forwardRef { const [isChecked, setIsChecked] = useState(defaultChecked ?? false); const [isDisabled, setIsDisabled] = useState(disabled ?? false); + const generatedId = React.useId(); + const inputId = id ?? generatedId; + const labelId = `${inputId}-label`; + const descriptionId = `${inputId}-description`; + const ariaLabelledBy = + props["aria-label"] || props["aria-labelledby"] ? props["aria-labelledby"] : labelId; const buttonClassName = variants[variant].button; const labelClassName = variants[variant].label; @@ -109,7 +115,7 @@ export const CheckboxWithLabel = React.forwardRef { - //returning false is not setting the state to false, it stops the event from bubbling up - if (isDisabled || props.readOnly === true) return false; - setIsChecked((c) => !c); - }} > { - //returning false is not setting the state to false, it stops the event from bubbling up - if (isDisabled || props.readOnly === true) return false; - setIsChecked(!isChecked); + if (isDisabled || props.readOnly === true) return; + setIsChecked(e.target.checked); }} disabled={isDisabled} className={cn( @@ -145,22 +150,21 @@ export const CheckboxWithLabel = React.forwardRef
- + {badges && ( {badges.map((badge) => ( @@ -170,12 +174,16 @@ export const CheckboxWithLabel = React.forwardRef {variant === "description" && ( - + {description} )}
-
+ ); } );