-
-
Notifications
You must be signed in to change notification settings - Fork 5.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixed onBlur callback on NumberInput and AutocompleteInput #9730
base: master
Are you sure you want to change the base?
Fixed onBlur callback on NumberInput and AutocompleteInput #9730
Conversation
…y passed to the onBlur handler
…onBlur handler of the `AutocompleteInput`
Any clues why |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know why the mobile e2e tests are failing, you'll have to investigate.
@@ -153,7 +153,9 @@ export type InputProps<ValueType = any> = Omit< | |||
export type UseInputValue = { | |||
id: string; | |||
isRequired: boolean; | |||
field: ControllerRenderProps; | |||
field: Omit<ControllerRenderProps, 'onBlur'> & { | |||
onBlur: (...event: any[]) => void; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why don't you use React's built-in FocusEventHandler?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I relied on implementation of onBlur function in useInput
react-admin/packages/ra-core/src/form/useInput.ts
Lines 97 to 102 in e87f8f4
const onBlur = useEvent((...event: any[]) => { | |
controllerField.onBlur(); | |
if (initialOnBlur) { | |
initialOnBlur(...event); | |
} | |
}); |
and onBlur of InputProps where type is written in such way.
There are also 2 cases where the FocusEventHandler will fail the type contract.
- A component needs to blur the input (BooleanInput, RichTextInput, FileInput, CheckboxGroupInput) because FocusEventHandler requires event as an argument.
const handleChange = useCallback(
event => {
field.onChange(event);
// Ensure field is considered as touched
field.onBlur();
},
[field]
);
- RichTextInput provides EditorEvents['blur'] instead, which doesn't match with the FocusEvent.
Here is the solution I came up that matches type contracts. If you like it i'll commit it
field: Omit<ControllerRenderProps, 'onBlur'> & {
onBlur: (
event?:
| FocusEvent<HTMLInputElement | HTMLTextAreaElement>
| EditorEvents['blur']
) => void;
};
yanchesky#1 |
Fixes #9726