[InputBase] Allow undefined in onBlur event type#45994
[InputBase] Allow undefined in onBlur event type#45994unclebay143 wants to merge 1 commit intomui:masterfrom
undefined in onBlur event type#45994Conversation
Netlify deploy previewhttps://deploy-preview-45994--material-ui.netlify.app/ Bundle size report |
undefined in onBlur event type
There was a problem hiding this comment.
@unclebay143 Thanks for opening the PR, but the solution isn't correct.
Only the event parameter type should be undefined not the onBlur prop. So, we need to change it to:
- onBlur?: React.FocusEventHandler<HTMLInputElement | HTMLTextAreaElement>;
+ onBlur?: {
+ bivarianceHack(
+ event: React.FocusEvent<HTMLInputElement | HTMLTextAreaElement> | undefined,
+ ): void;
+ }['bivarianceHack'];We can't do:
onBlur?: React.EventHandler<React.FocusEvent<HTMLInputElement | HTMLTextAreaElement> | undefined>;because SyntheticEvent doesn't support undefined.
But this would be a breaking change because now the developer would need to access the event properties using the optional chaining operator event?.target.
I'll add a comment in #45982 that this is a breaking change so we won't be able to release this in a minor or patch version.
|
Closing this since this is a breaking change. We can add it in the next major. |
|
That make sense, thanks for the feedback, looking forward to the fix in the major. |
Fixes #45982: Add
undefinedtoonBlurevent type inInputBaseProblem:
InputBasecallsonBlurwithundefinedin some cases (e.g., when disabled), but the type didn’t reflect this.Solution:
Updated the type to: