Open eps1lon opened 3 years ago
Hello eps1lon.
I do not understand your bug..
JS does not allow "readonly" attribute for input[type="radio"], instead, you can add the "disabled" attribute if you do not want to allow the user change it.
What exactly are you trying to achieve?
JS does not allow "readonly" attribute for input[type="radio"],
I understand. But React is recommending it.
Secondly, the controlled value being lost is problematic if there's a delay between onChange and the value being registered (e.g. if a server is inbetween). Right now the only safe mode for input[type="radio"]
is uncontrolled.
@eps1lon then adding disabled is your only optimal fix for your issue. adding a read-only has no add on or any enhancement for your request.
Anyway share React recommendation for the read-only input for extra validity
adding a read-only has no add on or any enhancement for your request.
I'm not asking for read-only. I'm showcasing how a controlled radio can become uncontrolled/out-of-sync in todays react.
React recommending read-only for checkbox/radio is a separate issue.
React version: 16.13.1 and 17.0.0-alpha.0-2d131d782
Steps To Reproduce
input[type="radio"][name="radio"]
: one is checked, one isn'tonChange
orreadOnly
onChange
to bothLink to code example:
The current behavior
readOnly
forinput[type="radio"]
even though this isn't supported natively (though React could polyfill it)The expected behavior
Arrow key navigation shouldn't break out of the controlled value. It's debateable whether React should recommend
readOnly
when this isn't a standard attribute likereadOnly
for<input type="text" />
.