mui / material-ui

Material UI: Comprehensive React component library that implements Google's Material Design. Free forever.
https://mui.com/material-ui/
MIT License
93.89k stars 32.26k forks source link

[TextField] TS error when TextField select multiple onChange signature uses 2 arguments #34816

Open Rc85 opened 2 years ago

Rc85 commented 2 years ago

Duplicates

Latest version

Steps to reproduce 🕹

Steps:

  1. Create TextField with select prop and SelectProps[mulitple]
  2. Pass a function with two arguments as you would when using Select with multiple

Current behavior 😯

TS will throw error

Type '(e: any, child: any) => void' is not assignable to type 'ChangeEventHandler<HTMLInputElement | HTMLTextAreaElement>'.

Expected behavior 🤔

When using multiple select, the second argument is the clicked option. Putting the @ts-ignore on the error and console logging the second argument will show the object, as you would on the Select component.

Context 🔦

No response

Your environment 🌎

npx @mui/envinfo ``` System: OS: Windows 10 10.0.19042 CPU: (16) x64 AMD Ryzen 7 2700X Eight-Core Processor Memory: 11.70 GB / 31.93 GB Binaries: Node: 16.15.0 - C:\Program Files\nodejs\node.EXE Yarn: 1.22.10 - ~\AppData\Roaming\npm\yarn.CMD npm: 8.5.5 - C:\Program Files\nodejs\npm.CMD Watchman: 20210102.202219.0 - C:\Users\roger\watchman\bin\watchman.EXE Utilities: Git: 2.30.0. IDEs: Android Studio: AI-212.5712.43.2112.8815526 VSCode: 1.71.2 - C:\Users\roger\AppData\Local\Programs\Microsoft VS Code\bin\code.CMD Visual Studio: 15.9.28307.1401 (Visual Studio Community 2017) Languages: Bash: 5.0.17 - C:\Windows\system32\bash.EXE Java: 17.0.1 Python: 2.7.18 Databases: PostgreSQL: 10.15 - C:\Program Files\PostgreSQL\10\bin\postgres.EXE SQLite: 3.32.2 - C:\platform-tools\sqlite3.EXE Browsers: Edge: Spartan (44.19041.1266.0), Chromium (106.0.1370.47) Internet Explorer: 11.0.19041.1202 ```
michaldudak commented 2 years ago

This is somehow related to #33742. We are going to revise the Select in the future major version when MUI Base is used as the underlying implementation. I'd personally be in favor of removing the select prop from the TextField and having a dedicated component for a select in form control.