mui / mui/material-ui

[material-ui][Autocomplete] onInputChange called with undefined event contrary to type definition

Open
#43,899 2 comments 4 reactions 1 assignee View on GitHub

Nobody has claimed this yet.

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

Description

Steps to reproduce

Link to live example: (required) https://stackblitz.com/edit/react-ouzbqw?file=Demo.tsx

Steps:

  1. Set the onInputChange prop
  2. Check what is passed in for the event param
Current behavior

Hello 👋

I'm noticing that the onInputChange is typed as:

onInputChange?: (
    event: React.SyntheticEvent,
    value: string,
    reason: AutocompleteInputChangeReason,
) => void;

with a non-null event param, but null seems to be coming through for the param on mount. See demo:

onInputChange-null-event

Expected behavior

I'm not sure if onInputChange is supposed to be called on mount or not, but if it is and it's expected that null is an option for event, would it be possible to update the typing of onInputChange to reflect that?

Thanks!

Context

We are trying to use strict null safety

Your environment

See https://stackblitz.com/edit/react-ouzbqw?file=Demo.tsx - also reproduce-able in this docs demo

Search keywords: onInputChange undefined event

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.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.