Skip to content

Commit fea1569

Browse files
committed
fix: pass checkbox state in onFocus and onBlur callbacks
Updates all CheckboxWidget implementations to use the actual checked state from the event target in onFocus and onBlur handlers instead of the component's value prop. This ensures callbacks receive the current checkbox state rather than potentially stale values from the component props.
1 parent 80e0206 commit fea1569

File tree

3 files changed

+22
-16
lines changed

3 files changed

+22
-16
lines changed

packages/daisyui/src/widgets/CheckboxWidget/CheckboxWidget.tsx

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,19 +42,25 @@ export default function CheckboxWidget<
4242

4343
/** Handle focus events
4444
*/
45-
const handleFocus = useCallback(() => {
46-
if (onFocus) {
47-
onFocus(id, value);
48-
}
49-
}, [onFocus, id, value]);
45+
const handleFocus = useCallback(
46+
(event: FocusEvent<HTMLInputElement>) => {
47+
if (onFocus) {
48+
onFocus(id, event.target.checked);
49+
}
50+
},
51+
[onFocus, id],
52+
);
5053

5154
/** Handle blur events
5255
*/
53-
const handleBlur = useCallback(() => {
54-
if (onBlur) {
55-
onBlur(id, value);
56-
}
57-
}, [onBlur, id, value]);
56+
const handleBlur = useCallback(
57+
(event: FocusEvent<HTMLInputElement>) => {
58+
if (onBlur) {
59+
onBlur(id, event.target.checked);
60+
}
61+
},
62+
[onBlur, id],
63+
);
5864

5965
/** Handle change events
6066
*

packages/primereact/src/CheckboxWidget/CheckboxWidget.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,10 @@ export default function CheckboxWidget<
4747
);
4848

4949
const required = schemaRequiresTrueValue<S>(schema);
50-
const _onChange = (e: CheckboxChangeEvent) => onChange && onChange(e.checked);
51-
const _onBlur = () => onBlur && onBlur(id, value);
52-
const _onFocus = () => onFocus && onFocus(id, value);
5350
const checked = value === 'true' || value === true;
51+
const _onChange = (e: CheckboxChangeEvent) => onChange && onChange(e.checked);
52+
const _onBlur = (e: FocusEvent<HTMLInputElement>) => onBlur && onBlur(id, e.target.checked);
53+
const _onFocus = (e: FocusEvent<HTMLInputElement>) => onFocus && onFocus(id, e.target.checked);
5454
const description = options.description ?? schema.description;
5555
const primeProps = (options.prime || {}) as object;
5656

packages/semantic-ui/src/CheckboxWidget/CheckboxWidget.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,10 @@ export default function CheckboxWidget<
5858
// the "required" attribute if the field value must be "true", due to the
5959
// "const" or "enum" keywords
6060
const required = schemaRequiresTrueValue<S>(schema);
61-
const _onChange = (_: FormEvent<HTMLInputElement>, data: CheckboxProps) => onChange && onChange(data.checked);
62-
const _onBlur = () => onBlur && onBlur(id, value);
63-
const _onFocus = () => onFocus && onFocus(id, value);
6461
const checked = value == 'true' || value == true;
62+
const _onChange = (_: FormEvent<HTMLInputElement>, data: CheckboxProps) => onChange && onChange(data.checked);
63+
const _onBlur = (event: FocusEvent<HTMLInputElement>) => onBlur && onBlur(id, event.currentTarget.checked);
64+
const _onFocus = (event: FocusEvent<HTMLInputElement>) => onFocus && onFocus(id, event.currentTarget.checked);
6565
const description = options.description ?? schema.description;
6666

6767
return (

0 commit comments

Comments
 (0)