-
-
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
Fix <NumberInput>
and <AutocompleteInput>
do not forward the event when calling onBlur
#9730
Fix <NumberInput>
and <AutocompleteInput>
do not forward the event when calling onBlur
#9730
Conversation
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;
};
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.
Sorry it took so long to answer. Yes, this new type looks fine
yanchesky#1 |
All e2e tests pass locally. Probably a random CI failure |
Are there any other steps I should take in order to finalise this PR? |
Can you implement the |
…y passed to the onBlur handler
…onBlur handler of the `AutocompleteInput`
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.
lgtm
But can you also please fix the conflict with the base branch?
Thanks
bec20f1
to
7600dca
Compare
Instead of adding a new |
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.
Thanks!
<NumberInput>
and <AutocompleteInput>
do not forward the event when calling onBlur
Fixes #9726