Skip to content

Commit f8378c4

Browse files
Handle undefined target in onBlur and onFocus handlers (#4227)
There are some instances where the `onBlur` and `onFocus` handlers are receiving an undefined `target`, causing the following type error: ``` Cannot read properties of undefined (reading 'value') ``` - Updated all of the `onBlur()` and `onFocus()` handlers in all libraries to fix this - Updated the `CHANGELOG.md` accordingly
1 parent 7bcfc4a commit f8378c4

File tree

45 files changed

+152
-115
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+152
-115
lines changed

CHANGELOG.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,43 @@ should change the heading of the (upcoming) version to include a major version b
1818

1919
# 5.18.5
2020

21+
## @rfsf/antd
22+
23+
- Updated widgets to handle undefined `target` in `onFocus` and `onBlur` handlers
24+
25+
## @rfsf/bootstrap4
26+
27+
- Updated widgets to handle undefined `target` in `onFocus` and `onBlur` handlers
28+
29+
## @rfsf/chakra-ui
30+
31+
- Updated widgets to handle undefined `target` in `onFocus` and `onBlur` handlers
32+
2133
## @rjsf/core
2234

2335
- Fix case where NumberField would not properly reset the field when using programmatic form reset (#4202)[https://github.com/rjsf-team/react-jsonschema-form/issues/4202]
36+
- Updated widgets to handle undefined `target` in `onFocus` and `onBlur` handlers
37+
38+
## @rfsf/fluent-ui
39+
40+
- Updated widgets to handle undefined `target` in `onFocus` and `onBlur` handlers
41+
42+
## @rfsf/fluentui-rc
43+
44+
- Updated widgets to handle undefined `target` in `onFocus` and `onBlur` handlers
45+
46+
## @rfsf/material-ui
47+
48+
- Updated widgets to handle undefined `target` in `onFocus` and `onBlur` handlers
49+
50+
## @rfsf/mui
51+
52+
- Updated widgets to handle undefined `target` in `onFocus` and `onBlur` handlers
53+
54+
## @rfsf/semantic-ui
55+
56+
- Updated widgets to handle undefined `target` in `onFocus` and `onBlur` handlers
57+
2458

2559
## @rjsf/validator-ajv6
2660

packages/antd/src/templates/BaseInputTemplate/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,9 @@ export default function BaseInputTemplate<
5050
? onChangeOverride
5151
: ({ target }: ChangeEvent<HTMLInputElement>) => onChange(target.value === '' ? options.emptyValue : target.value);
5252

53-
const handleBlur = ({ target }: FocusEvent<HTMLInputElement>) => onBlur(id, target.value);
53+
const handleBlur = ({ target }: FocusEvent<HTMLInputElement>) => onBlur(id, target && target.value);
5454

55-
const handleFocus = ({ target }: FocusEvent<HTMLInputElement>) => onFocus(id, target.value);
55+
const handleFocus = ({ target }: FocusEvent<HTMLInputElement>) => onFocus(id, target && target.value);
5656

5757
const input =
5858
inputProps.type === 'number' || inputProps.type === 'integer' ? (

packages/antd/src/templates/WrapIfAdditionalTemplate/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ export default function WrapIfAdditionalTemplate<
6565
);
6666
}
6767

68-
const handleBlur = ({ target }: FocusEvent<HTMLInputElement>) => onKeyChange(target.value);
68+
const handleBlur = ({ target }: FocusEvent<HTMLInputElement>) => onKeyChange(target && target.value);
6969

7070
// The `block` prop is not part of the `IconButtonProps` defined in the template, so put it into the uiSchema instead
7171
const uiOptions = uiSchema ? uiSchema[UI_OPTIONS_KEY] : {};

packages/antd/src/widgets/CheckboxWidget/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ export default function CheckboxWidget<
2525

2626
const handleChange: NonNullable<CheckboxProps['onChange']> = ({ target }) => onChange(target.checked);
2727

28-
const handleBlur = ({ target }: FocusEvent<HTMLInputElement>) => onBlur(id, target.checked);
28+
const handleBlur = ({ target }: FocusEvent<HTMLInputElement>) => onBlur(id, target && target.checked);
2929

30-
const handleFocus = ({ target }: FocusEvent<HTMLInputElement>) => onFocus(id, target.checked);
30+
const handleFocus = ({ target }: FocusEvent<HTMLInputElement>) => onFocus(id, target && target.checked);
3131

3232
// Antd's typescript definitions do not contain the following props that are actually necessary and, if provided,
3333
// they are used, so hacking them in via by spreading `extraProps` on the component to avoid typescript errors

packages/antd/src/widgets/RadioWidget/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@ export default function RadioWidget<T = any, S extends StrictRJSFSchema = RJSFSc
3737
onChange(enumOptionsValueForIndex<S>(nextValue, enumOptions, emptyValue));
3838

3939
const handleBlur = ({ target }: FocusEvent<HTMLInputElement>) =>
40-
onBlur(id, enumOptionsValueForIndex<S>(target.value, enumOptions, emptyValue));
40+
onBlur(id, enumOptionsValueForIndex<S>(target && target.value, enumOptions, emptyValue));
4141

4242
const handleFocus = ({ target }: FocusEvent<HTMLInputElement>) =>
43-
onFocus(id, enumOptionsValueForIndex<S>(target.value, enumOptions, emptyValue));
43+
onFocus(id, enumOptionsValueForIndex<S>(target && target.value, enumOptions, emptyValue));
4444

4545
const selectedIndexes = enumOptionsIndexForValue<S>(value, enumOptions) as string;
4646

packages/antd/src/widgets/TextareaWidget/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ export default function TextareaWidget<
3838
const handleChange = ({ target }: ChangeEvent<HTMLTextAreaElement>) =>
3939
onChange(target.value === '' ? options.emptyValue : target.value);
4040

41-
const handleBlur = ({ target }: FocusEvent<HTMLTextAreaElement>) => onBlur(id, target.value);
41+
const handleBlur = ({ target }: FocusEvent<HTMLTextAreaElement>) => onBlur(id, target && target.value);
4242

43-
const handleFocus = ({ target }: FocusEvent<HTMLTextAreaElement>) => onFocus(id, target.value);
43+
const handleFocus = ({ target }: FocusEvent<HTMLTextAreaElement>) => onFocus(id, target && target.value);
4444

4545
// Antd's typescript definitions do not contain the following props that are actually necessary and, if provided,
4646
// they are used, so hacking them in via by spreading `extraProps` on the component to avoid typescript errors

packages/bootstrap-4/src/BaseInputTemplate/BaseInputTemplate.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ export default function BaseInputTemplate<
3939
};
4040
const _onChange = ({ target: { value } }: ChangeEvent<HTMLInputElement>) =>
4141
onChange(value === '' ? options.emptyValue : value);
42-
const _onBlur = ({ target: { value } }: FocusEvent<HTMLInputElement>) => onBlur(id, value);
43-
const _onFocus = ({ target: { value } }: FocusEvent<HTMLInputElement>) => onFocus(id, value);
42+
const _onBlur = ({ target }: FocusEvent<HTMLInputElement>) => onBlur(id, target && target.value);
43+
const _onFocus = ({ target }: FocusEvent<HTMLInputElement>) => onFocus(id, target && target.value);
4444

4545
// const classNames = [rawErrors.length > 0 ? "is-invalid" : "", type === 'file' ? 'custom-file-label': ""]
4646
return (

packages/bootstrap-4/src/CheckboxWidget/CheckboxWidget.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ export default function CheckboxWidget<
4444
);
4545

4646
const _onChange = ({ target: { checked } }: FocusEvent<HTMLInputElement>) => onChange(checked);
47-
const _onBlur = ({ target: { checked } }: FocusEvent<HTMLInputElement>) => onBlur(id, checked);
48-
const _onFocus = ({ target: { checked } }: FocusEvent<HTMLInputElement>) => onFocus(id, checked);
47+
const _onBlur = ({ target }: FocusEvent<HTMLInputElement>) => onBlur(id, target && target.checked);
48+
const _onFocus = ({ target }: FocusEvent<HTMLInputElement>) => onFocus(id, target && target.checked);
4949

5050
const description = options.description || schema.description;
5151
return (

packages/bootstrap-4/src/CheckboxesWidget/CheckboxesWidget.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@ export default function CheckboxesWidget<
3131
}
3232
};
3333

34-
const _onBlur = ({ target: { value } }: FocusEvent<HTMLInputElement>) =>
35-
onBlur(id, enumOptionsValueForIndex<S>(value, enumOptions, emptyValue));
36-
const _onFocus = ({ target: { value } }: FocusEvent<HTMLInputElement>) =>
37-
onFocus(id, enumOptionsValueForIndex<S>(value, enumOptions, emptyValue));
34+
const _onBlur = ({ target }: FocusEvent<HTMLInputElement>) =>
35+
onBlur(id, enumOptionsValueForIndex<S>(target && target.value, enumOptions, emptyValue));
36+
const _onFocus = ({ target }: FocusEvent<HTMLInputElement>) =>
37+
onFocus(id, enumOptionsValueForIndex<S>(target && target.value, enumOptions, emptyValue));
3838

3939
return (
4040
<Form.Group>

packages/bootstrap-4/src/RadioWidget/RadioWidget.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ export default function RadioWidget<T = any, S extends StrictRJSFSchema = RJSFSc
2626

2727
const _onChange = ({ target: { value } }: ChangeEvent<HTMLInputElement>) =>
2828
onChange(enumOptionsValueForIndex<S>(value, enumOptions, emptyValue));
29-
const _onBlur = ({ target: { value } }: FocusEvent<HTMLInputElement>) =>
30-
onBlur(id, enumOptionsValueForIndex<S>(value, enumOptions, emptyValue));
31-
const _onFocus = ({ target: { value } }: FocusEvent<HTMLInputElement>) =>
32-
onFocus(id, enumOptionsValueForIndex<S>(value, enumOptions, emptyValue));
29+
const _onBlur = ({ target }: FocusEvent<HTMLInputElement>) =>
30+
onBlur(id, enumOptionsValueForIndex<S>(target && target.value, enumOptions, emptyValue));
31+
const _onFocus = ({ target }: FocusEvent<HTMLInputElement>) =>
32+
onFocus(id, enumOptionsValueForIndex<S>(target && target.value, enumOptions, emptyValue));
3333

3434
const inline = Boolean(options && options.inline);
3535

0 commit comments

Comments
 (0)