Skip to content

Commit 79fac6e

Browse files
committed
Checkbox - fixed label click cases double click
1 parent a333f69 commit 79fac6e

File tree

4 files changed

+109
-112
lines changed

4 files changed

+109
-112
lines changed

library/src/components/Checkbox.tsx

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
type InputHTMLAttributes,
88
type ReactNode,
99
useEffect,
10+
useId,
1011
useImperativeHandle,
1112
useRef,
1213
useState,
@@ -139,6 +140,8 @@ const CheckboxI = (
139140
}
140141
}, [])
141142

143+
const bid = useId()
144+
142145
return (
143146
<>
144147
<div
@@ -151,7 +154,7 @@ const CheckboxI = (
151154
<div className={"relative flex items-center justify-center"}>
152155
<input
153156
type="checkbox"
154-
id={id}
157+
id={id ?? bid}
155158
data-testid={testId}
156159
ref={inputRef}
157160
disabled={disabled}
@@ -195,24 +198,12 @@ const CheckboxI = (
195198
</div>
196199

197200
<label
198-
htmlFor={id}
201+
htmlFor={id ?? bid}
199202
id={labelId}
200203
aria-disabled={disabled}
201204
aria-invalid={invalid}
202205
className={twMerge(labelStyles, labelClassName)}
203206
style={labelStyle}
204-
onClick={(e) => {
205-
if (disabled) {
206-
e.preventDefault()
207-
e.stopPropagation()
208-
}
209-
inputRef.current?.click()
210-
}}
211-
onKeyUp={(e) => {
212-
if (e.key === "Enter" && !disabled) {
213-
inputRef.current?.click()
214-
}
215-
}}
216207
>
217208
{label}
218209
</label>

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,13 +122,13 @@
122122
"lowlight": "^3.3.0",
123123
"lucide-react": "^0.544.0",
124124
"mime-types": "^3.0.1",
125-
"motion": "^12.23.20",
125+
"motion": "^12.23.21",
126126
"postcss": "^8.5.6",
127127
"react-awesome-slider": "^4.1.0",
128128
"react-day-picker": "^9.11.0",
129129
"react-intl": "^7.1.11",
130130
"react-joyride": "^2.9.3",
131-
"react-router-dom": "^7.9.1",
131+
"react-router-dom": "^7.9.2",
132132
"react-select": "^5.10.2",
133133
"react-syntax-highlighter": "^15.6.6",
134134
"react-transition-group": "^4.4.5",

0 commit comments

Comments
 (0)