mui / mui/material-ui

[TextField] When TextField is used as select, onChange handler type should be ChangeEvent<HTMLSelectElement>

Open
#33,742 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Duplicates
  • I have searched the existing issues
Latest version
  • I have tested the latest version
Current behavior 😯

When using a TextField as select (using the select prop), the onChange handler expects a function that receives a ChangeEvent<HTMLInputElement | HTMLTextAreaElement>

Expected behavior 🤔

It should accept a ChangeEvent<HTMLSelectElement>

Steps to reproduce 🕹

Reproduction: https://www.typescriptlang.org/play?#code/JYWwDg9gTgLgBAKjgQwM5wEoFNkGN4BmUEIcA5FDvmQFCiSxwCyWAdgK4CSMWpRJ5AAIh2wAPQhkPKMGQAbMSw7deZANx1w0eABUsADxgAxYFjkATOP1JlhoiVKwz5YvYZNnz6mjQMN45lgEyOxyhOys+MAQrMwAngDCJJCsbDAAFACUcADeNHBwuDGo8ADawKxg7DAANHCoWDCcldUAunAAvJhUMAB07A0AyjCO6WQEEBBkmRoFRawlcAAWyKzmclgJK6wA5lid3Xh9A5vycgBGeADW6elYAG5pAFyH+L1bq3sAoo+sMAA8AAkdEwADKDMxYfBfDYgNIAPmyHXhuXyBXqjWaVQyDzSvRGUD2fXu8nYWBmaIAvnVSq0KQVKDB2FBYuk0QV-m5jKYLBiNvg4CS5GSOjkKtjKXAYh9dlhRdt1pttntKfD2ej-kouDxSEKRQAiCYQfXwo3-RRsbW8NXouDmrkeCw2uAUyk0IA

Context 🔦

This is a minor issue with no real problematic consequences, the workaround is simple, use a ChangeEvent<HTMLInputElement>.

Your environment 🌎

No response

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 at the TextField component's select prop and inspect how its onChange handler type is declared for select usage. Use the linked TypeScript reproduction to confirm the current error; done means a select TextField accepts ChangeEvent without the workaround described.

Written by the indexing model from the issue text.

Assessment

Tech stack
react, typescript
Domain
frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.