react: Bug: Select when passed a value as Prop errors with a suggestion to pass readOnly
Seems weird when we try to use a select component, and pass a value as a prop, it prompts with the error to either set onChange or readOnly.
the readOnly at the last seems misleading since the select component does not have a readOnly prop, unlike inputs which do have a readOnly attribute.
SELECT PROPS https://react.dev/reference/react-dom/components/select
seems an easy fix would be to check if the mounted component is a select component and then conditionally just change the error message, though would need to add tests to support the same.
https://github.com/facebook/react/assets/72331432/12674152-7d57-4d98-99e6-635577b31bfe
cc @sophiebits
codesandbox link to tinker:- https://codesandbox.io/s/admiring-wright-9sctsn?file=/src/App.js
About this issue
- Original URL
- State: closed
- Created 8 months ago
- Comments: 16 (14 by maintainers)
Commits related to this issue
- fix: select console error to not suggest to set readonly to true (#27740) fix #27657 added test in the `ReactDOMSELECT-test.js` to not allow regession to happen in future. After changes this ... — committed to facebook/react by Biki-das 7 months ago
- fix: select console error to not suggest to set readonly to true (#27740) fix #27657 added test in the `ReactDOMSELECT-test.js` to not allow regession to happen in future. After changes this is wha... — committed to facebook/react by hoxyq 7 months ago
- fix: select console error to not suggest to set readonly to true (#27740) fix #27657 added test in the `ReactDOMSELECT-test.js` to not allow regession to happen in future. After changes this ... — committed to EdisonVan/react by Biki-das 7 months ago
- fix: select console error to not suggest to set readonly to true (#27740) fix #27657 added test in the `ReactDOMSELECT-test.js` to not allow regession to happen in future. After changes this is wha... — committed to facebook/react by hoxyq 7 months ago
IMHO, setting
onChangeto no-op is explicit and looks aligned with currentreact-domAPIs . Ifreact-dom’sselecthadhiddenattribute, we could’ve also took it into account before printing an error.Should be fixed with https://github.com/facebook/react/pull/27717.
Jest tests, probably? Or try checking out on some older commit. I’ve tried
main~100and it works.Can confirm that it doesn’t work for me also. Looks like a recent regression, but I don’t have the time now to bisect the PR, which introduced this. I’ve validated that sourcemaps PRs are not related to it, so there is some commit prior to it that breaks this.
@hoxyq can you change the status to confirmed if possible?
ok will look up we have holidays here till next week. seems an easy fix would need to inspect the component and filter the message and add tests to support the same 😃
I think it is worth fixing, especially given the fact that https://react.dev/reference/react-dom/components/select doesn’t list
readOnlyas an attribute.I am not familiar with the code where this happens, but maybe its worth just implementing its own validation for
selectcomponent.