-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
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
[TextField] onBlur event argument might be undefined #16402
Comments
@shartte This is a new logic that was introduced in #15446. I would propose one of these two options:
|
Sounds like the safer option to me. |
Yeah, if the current behavior stays in place, it should at least be documented, if possible, also on the InputBase page (onBlur is currently absent there since it's forwarded to the native element I assume). |
@shartte I would suggest you had a closer look at the pull request. It's not an accurate fact. @eps1lon I don't know, both options have their pros & cons. I can't resolve to one of these two options 🤷♂️. If you have a preference for n°2, why not! |
@shartte Could you share with us the context in which you have noticed this behavior? I think that it will help us take a better tradeoff. |
@oliviertassinari Ah you're right, I mistook the test code for the actual implementation. Sorry! |
Updating the typescript definition definitely makes sense if the current behaviour stays. Perhaps there should be a section on the documentation as well? So users not using typescript could potentially look there or maybe something in the prop description is better |
I think that we can go with option n°2 with the TypeScript update, prop type description update and linking the React issue in a comment. We can always revert later on to option n°1 if people still get errors in production because they try to access event.x in the blur event. |
I would propose the following diff: diff --git a/packages/material-ui/src/InputBase/InputBase.js b/packages/material-ui/src/InputBase/InputBase.js
index e425bd307..5a18eb47d 100644
--- a/packages/material-ui/src/InputBase/InputBase.js
+++ b/packages/material-ui/src/InputBase/InputBase.js
@@ -548,7 +548,9 @@ InputBase.propTypes = {
*/
name: PropTypes.string,
/**
- * @ignore
+ * Callback fired when the input is blurred.
+ *
+ * Notice that the first argument (event) might be undefined.
*/
onBlur: PropTypes.func,
/** @shartte Do you want to work on it? |
@oliviertassinari I saw that he didn't answer so I decided to take this one. |
@abnersajr The InputBase.ts.d has the following code:
The React types define FocusEventHandler as:
That definition does not allow for the function parameter to be undefined, so Material-UI is using the wrong type. It could instead use (not tested, just off the top of my head):
|
@oliviertassinari Looks like this is not closed... Typescript defintion is wrong - now onBlur handler (according to d.ts file) always receive event object: https://github.com/mui/material-ui/blob/master/packages/mui-material/src/InputBase/InputBase.d.ts#L134 |
@oliviertassinari please re-open this issue. In MUI 5.11.12 the event is not marked as nullable/optional We actually just run into an runtime error because of this, thats how I ended up on this thread |
This seems like a revival of #9027, and causes event handlers which expect to be passed an event object to fail, since it'll be
undefined
.The offending line of code is here:
https://github.com/mui-org/material-ui/blob/46af75d63b249e24872d481c99ceaa9d4a5f6e21/packages/material-ui/src/InputBase/InputBase.js#L223
This might have been introduced in the conversion to a function component, but I am unsure.
The previous fix was simply passing {} as the event object as it'll at least fix the direct issue of accessing properties of
undefined
.The text was updated successfully, but these errors were encountered: