Skip to content

Commit ed33b99

Browse files
committed
fix(webapp): use native checkbox label semantics
1 parent f0b2691 commit ed33b99

2 files changed

Lines changed: 7 additions & 15 deletions

File tree

.oxlintrc.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@
8686
],
8787
"jsx-a11y/label-has-associated-control": "error",
8888
"jsx-a11y/no-autofocus": "off",
89-
"jsx-a11y/no-noninteractive-element-interactions": "off",
89+
"jsx-a11y/no-noninteractive-element-interactions": "error",
9090
"jsx-a11y/no-static-element-interactions": "off",
9191
"jsx-a11y/prefer-tag-over-role": "off",
9292
"jsx-a11y/anchor-ambiguous-text": "error",

apps/webapp/app/components/primitives/Checkbox.tsx

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)