mui / mui/material-ui

[material-ui][InputBase] onBlur called with undefined event contrary to type definition

Open
#45,982 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

breaking change scope: text field typescript
Dominant language
JavaScript
Stars
99.1k
Forks
32.5k
Avg merge
2d 17h
Merged PRs (30d)
106

Description

Hello 👋

Search keywords

undefined event onBlur

Latest version
  • I have tested the latest version
Steps to reproduce

Steps:

  1. Open this link to live example: https://stackblitz.com/edit/react-zufzmfhc?file=Demo.tsx
  2. Type something in the input
  3. See in the console that the event passed to onBlur is undefined if the InputBase is disabled
Current behavior

InputBase is calling onBlur with an undefined event in certain cases, but the type definition for onBlur does not have a nullable event:

/**
* Callback fired when the `input` is blurred.
*
* Notice that the first argument (event) might be undefined.
*/
onBlur?: React.FocusEventHandler<HTMLInputElement | HTMLTextAreaElement>;

Even though there is a comment, undefined is not an option for the events.

Expected behavior

I would have expected the behavior of the onBlur to match the type definition and no undefined event to be passed in. Would it be possible to either update the type definition to include undefined or update the onBlur call to pass in an event for InputBase?

Context

We are running with strict null safety and this is causing an issue.

Your environment

See sandbox: https://stackblitz.com/edit/react-zufzmfhc?file=Demo.tsx

Thank you!

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with packages/mui-material/src/InputBase/InputBase.js at the linked onBlur call and compare it with the onBlur declaration in packages/mui-material/src/InputBase/InputBase.d.ts. Reproduce the disabled-input case using the linked StackBlitz example, then verify that the runtime behavior and type definition agree.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, react
Domain
frontend
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.