Conversation
MUI v9 removed InputProps, inputProps and InputLabelProps from TextField, and inputProps from Checkbox. react-admin still passed them alongside the slotProps equivalents, so on MUI v9 they reached the DOM and triggered React unknown-prop warnings. Only pass the legacy props on the MUI versions that still support them.
Both inputs forwarded the form ref through FormControlLabel's inputRef. MUI v9 removed inputRef from Switch and Checkbox, so the ref never reached the <input> and react-hook-form's setFocus() did nothing. Pass the ref through slotProps.input.ref on MUI v7+, and keep inputRef on older versions, where Switch/Checkbox slotProps.input may not exist.
The buttons had no type, so they defaulted to submit. Clicking them also submitted the form and called the default dataProvider's create, which returns { data: null } and crashed in validateResponseFormat.
| // Checkbox slotProps were only added in MUI v6.4 | ||
| {...(muiMajor < 7 | ||
| ? { inputProps: selectAllInputProps } | ||
| : {})} |
There was a problem hiding this comment.
We can make this ternary operator muiMajor < 7 ? { inputProps: selectAllInputProps } : { slotProps: { input: selectAllInputProps } } maybe this will look slightly better?
Also if the old code says muiMajor >= 6 but in your comment Checkbox slotProps were only added in MUI v6.4 then there is a conflict. The peerDependency for @mui/material need to be bumped from "^5.16.12 || ^6.0.0 || ^7.0.0 || ^9.0.0" to "^5.16.12 || ^6.4.0 || ^7.0.0 || ^9.0.0"
There was a problem hiding this comment.
I saw your question in discord https://discord.com/channels/830711057643208724/1552655977608908911 Thanks for pointing that out.
There was a problem hiding this comment.
Good idea, thanks! Applied the ternary here and in SelectPageCheckbox, which had the same pattern.
About the peerDependency: that's actually why the gate is < 7 instead of < 6. slotProps.input is only used on MUI v7+, where it's always supported, while MUI v6.0–6.3 still get inputProps, which works there. So ^6.0.0 stays valid and we don't need to drop support for 6.0–6.3. I updated the comment to make the reasoning clearer. Happy to bump it if you prefer, though.
PS: I am trusting AI here since I am a bit confused :)
Description
Fix inputs passing props removed in MUI v9
Problem
Since #11248 added MUI v9 to the peer dependencies (#11241), several inputs still pass props that MUI v9 removed:
InputProps,inputPropsandInputLabelPropsonTextField(ResettableTextField,NumberInput,DateInput,DateTimeInput,TimeInput,AutocompleteInput)inputPropsonCheckbox(DatagridHeader,SelectPageCheckbox)inputRefonSwitch/Checkbox(BooleanInput,CheckboxGroupInput)On MUI v9 these props reach the DOM and React logs unknown-prop warnings.
The
inputRefone is also a functional bug:BooleanInputandCheckboxGroupInputforward the form ref throughFormControlLabel'sinputRef, so on MUI v9 the ref never reaches the<input>andsetFocus()from react-hook-form does nothing (the use case fixed in #9202).Solution
muiMajorgating pattern. TheslotPropsequivalents were already passed on MUI v6+.BooleanInputandCheckboxGroupInput, forward the ref throughslotProps.input.refon MUI v7+, and keepinputRefon older versions. The gate is< 7rather than< 6becauseSwitch/Checkboxonly supportslotProps.inputsince MUI v6.4.type="button"to theSetFocusstory buttons ofBooleanInput,CheckboxGroupInputandNumberInput. Without it the button submitted the form, which crashed with the default dataProvider (createreturns{ data: null }).AutocompleteInputonly gets the minimal change here (not passingInputPropson v9). On MUI v9,renderInputreceivesparams.slotPropsinstead ofparams.InputProps; I'll handle that in a separate PR to keep this one small.How To Test
SetFocusstories:react-admin5.15.4 and@mui/material9.x, with a button callingsetFocus('published')next to a<BooleanInput source="published" />:inputRef/InputProps/InputLabelPropswarnings.ra-ui-materialuibuild): the switch gets focus, Space toggles it, and these warnings are gone for the changed inputs.What I verified:
ra-ui-materialuisuite passes (1204 passed), along with lint, prettier andtsc.masterand pass with this branch. The removed-prop warnings in thera-ui-materialuisuite drop from 728 to 4, and those 4 come fromSelectInput.spec.tsxitself. MUI v9 also emits unrelated prop-type warnings (e.g.Invalid prop 'children' supplied to 'ThemeProvider'), which make many tests fail onmastertoo, so I ran these with that noise ignored.TextFieldslotProps since v6.0,Switch/CheckboxslotProps.inputsince v6.4.6).Additional Checks
masterfor a bugfix or a documentation fix, ornextfor a featureSetFocusstories, fixed so they no longer submit the form