Skip to content

Commit 373b40d

Browse files
authored
Merge pull request #19 from HediMuhamad/fix--ignoring-passed-onBlur-property
Fixing ignoring passed onBlur properties to controllers
2 parents 1246e73 + e0ba7f8 commit 373b40d

File tree

13 files changed

+46
-8
lines changed

13 files changed

+46
-8
lines changed

src/components/InputController/AutocompleteController/AutocompleteController.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ export const AutocompleteController = ({
2727
loading = false,
2828
onChange,
2929
customOptionLabel,
30+
onBlur,
3031
...rest
3132
}: AutocompleteControllerProps) => {
3233
return loading ? (
@@ -39,7 +40,7 @@ export const AutocompleteController = ({
3940
control={control}
4041
name={name}
4142
defaultValue={multiple ? defaultValue || [] : defaultValue || null}
42-
render={({ field: { onChange: fieldOnChange, ref, ...restField }, fieldState }) => {
43+
render={({ field: { onChange: fieldOnChange, onBlur: fieldOnBlur, ref, ...restField }, fieldState }) => {
4344
return (
4445
<Autocomplete
4546
options={options || []}
@@ -82,6 +83,10 @@ export const AutocompleteController = ({
8283
: get(newValue, optionValue, null)
8384
);
8485
}}
86+
onBlur={(...args) => {
87+
onBlur?.(...args);
88+
fieldOnBlur?.();
89+
}}
8590
{...rest}
8691
renderInput={(params) => {
8792
return (

src/components/InputController/CheckboxController/CheckboxController.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export const CheckboxController: React.FC<CheckboxControllerProps> = ({
1111
label,
1212
defaultValue,
1313
onChange,
14+
onBlur,
1415
...rest
1516
}) => {
1617
return (
@@ -33,6 +34,10 @@ export const CheckboxController: React.FC<CheckboxControllerProps> = ({
3334
onChange?.(e);
3435
field.onChange(e.target.checked);
3536
}}
37+
onBlur={(...args) => {
38+
onBlur?.(...args);
39+
field.onBlur();
40+
}}
3641
/>
3742
}
3843
/>

src/components/InputController/RadioGroupController/RadioGroupController.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export const RadioGroupController: React.FC<RadioGroupControllerProps> = ({
1212
control,
1313
options,
1414
onChange,
15+
onBlur,
1516
...rest
1617
}) => {
1718
return (
@@ -29,6 +30,10 @@ export const RadioGroupController: React.FC<RadioGroupControllerProps> = ({
2930
onChange?.(event);
3031
field.onChange(event);
3132
}}
33+
onBlur={(...args) => {
34+
field?.onBlur?.();
35+
onBlur?.(...args);
36+
}}
3237
>
3338
{options.map((option, index) => (
3439
<FormControlLabel

src/components/InputController/SelectController/SelectController.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ export const SelectController = ({
3737
defaultValue,
3838
options,
3939
onChange,
40+
onBlur,
4041
optionValue = 'value',
4142
optionLabel = 'label',
4243
loading = false,
@@ -81,6 +82,10 @@ export const SelectController = ({
8182
onChange?.(event);
8283
restField.onChange(event);
8384
}}
85+
onBlur={(...args) => {
86+
restField?.onBlur?.();
87+
onBlur?.(...args);
88+
}}
8489
disabled={restField.disabled ?? rest.disabled}
8590
>
8691
{options?.map((option, index) => {

src/components/InputController/SwitchController/SwitchController.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export const SwitchController: React.FC<SwitchControllerProps> = ({
1414
label,
1515
defaultValue = false,
1616
onChange,
17+
onBlur,
1718
...rest
1819
}) => {
1920
const [isChecked, setIsChecked] = useState(defaultValue);
@@ -39,6 +40,10 @@ export const SwitchController: React.FC<SwitchControllerProps> = ({
3940
field.onChange(Boolean(event.target.checked));
4041
onChange && onChange(event);
4142
}}
43+
onBlur={(...args) => {
44+
field?.onBlur?.();
45+
onBlur?.(...args);
46+
}}
4247
/>
4348
}
4449
label={label}

src/components/InputController/TextFieldController/TextFieldController.tsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ export const TextFieldController: React.FC<TextFieldControllerProps> = ({
88
control,
99
defaultValue,
1010
type,
11+
onChange,
12+
onBlur,
1113
...rest
1214
}) => {
1315
return (
@@ -31,6 +33,14 @@ export const TextFieldController: React.FC<TextFieldControllerProps> = ({
3133
{...rest}
3234
inputRef={ref}
3335
{...restField}
36+
onChange={(...args) => {
37+
restField?.onChange?.(...args);
38+
onChange?.(...args);
39+
}}
40+
onBlur={(...args) => {
41+
restField?.onBlur?.();
42+
onBlur?.(...args);
43+
}}
3444
disabled={restField.disabled ?? rest.disabled}
3545
/>
3646
);

src/fields/typing.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ export type SwitchControllerProps = MuiRhfFieldProps & {
4040
label: string;
4141
defaultValue?: boolean;
4242
onChange?: (event: React.ChangeEvent<HTMLInputElement>) => void;
43+
onBlur?: (event: React.FocusEvent<HTMLButtonElement>) => void;
4344
};
4445

4546
// RadioGroup
@@ -48,13 +49,15 @@ export type RadioGroupControllerProps = MuiRhfFieldProps & {
4849
defaultValue: string | number;
4950
options: Array<Option>;
5051
onChange?: (event: React.ChangeEvent<HTMLInputElement>) => void;
52+
onBlur?: (event: React.FocusEvent<HTMLDivElement>) => void;
5153
};
5254

5355
// Checkbox
5456
export type CheckboxControllerProps = MuiRhfFieldProps & {
5557
label: string;
5658
defaultValue?: boolean;
5759
onChange?: (event: React.ChangeEvent<HTMLInputElement>) => void;
60+
onBlur?: (event: React.FocusEvent<HTMLButtonElement>) => void;
5861
};
5962

6063
// Autocomplete

src/stories/Autocomplete.stories.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ Autocomplete.args = {
5858
options: [
5959
{ title: 'Option One', entity: { id: 'entity-one' }, value: 'option-one' },
6060
{ title: 'Option two', entity: { id: 'entity-two' }, value: 'option-two' }
61-
]
61+
],
62+
onBlur: () => console.log('Autocomplete onBlur called')
6263
};
6364

6465
export const AutocompleteMultiple = Template.bind({});

src/stories/CheckboxController.stories.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,5 @@ export const Checkbox = Template.bind({});
3131

3232
Checkbox.args = {
3333
name: 'checkbox',
34-
label: 'Checkbox Controller'
34+
label: 'Checkbox Controller',
3535
};

src/stories/RadioGroup.stories.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,5 @@ FormGroup.args = {
3636
options: [
3737
{ label: 'Option 1', value: 'option1' },
3838
{ label: 'Option 2', value: 'option2' }
39-
]
39+
],
4040
};

0 commit comments

Comments
 (0)