TextField
inputProps
not passed to <input/>
#29525
Labels
bug 🐛
Something doesn't work
component: text field
This is the name of the generic UI component, not the React module!
Current Behavior 😯
Edit Title fully captures problem. MRE is below.
Expected Behavior 🤔
According to the API documentation for
TextField
,inputProps
should be passed down to the<input/>
element. However, this does not happen, as you can see in my MRE below.The HTML that gets output is:
You can see the
aria-label
I pass in via<TextField inputProps={{'aria-label':....
is being attached to the<div/>
rather than the<input/>
, which conflicts with the documentation.I've also tried
InputProps
andSelectProps={{ inputProps: { 'aria-label': ...
just to be certain. I tried tracing through the code, but I can't find the logic that decides to assign to the DIV instead of INPUT.Steps to Reproduce 🕹
Minimal reproducible example:
https://github.com/kylegoetz/material-ui-bug
Steps:
Context 🔦
I'm trying to unit test my components, which use Material UI form components. I'm using @testing-library/react, which advocates for accessibility-based testing, so you would
expect(getByLabelText('my aria label')).toHaveValue(expected)
but when yougetByLabelText
on this, you get the DIV, which has novalue
property.There are other solutions, but they closely couple the test to my implementation or otherwise fall short of accessibility-based testing, and if I switched from @material-ui, it would break all the closely-coupled tests (as it stands, switching from NativeSelect to TextField already breaks the tests because
inputProps
aren't being passed as per the documentation.Your Environment 🌎
`npx @mui/envinfo`
Browser is latest Chrome
The text was updated successfully, but these errors were encountered: