bug: RadioValueAccessor generated by angular-output-target overwrites the value of the radio input #434
Labels
help wanted
a good issue for the community
package: angular
@stencil/angular-output-target package
type: bug
Something isn't working
Prerequisites
Stencil Version
4.18.0
Stencil Framework Output Target
Angular
Stencil Framework Output Target Version
0.8.4
Current Behavior
When the angular FormControl is updated, the RadioValueAccessor overwrites the
value
attribute of any custom Stencil radio button components bound to the form control.For example, if the radio inputs are defined like this:
And the form control is defined like this:
Then the values in the rendered HTML are overridden to the value of the FormControl (in this case "option-1").

Since the values of all inputs are overwritten the value of the form control will remain "option-1" no matter which radio button is clicked.
Expected Behavior
The RadioValueAccessor should not overwrite the
value
attribute of a custom Stencil radio button component. Instead, it should only change the checked property.Using native HTML radio inputs with Angular formContol in the same way works as expected and the
value
attribute of the native inputs is not overwritten. When a radio input is clicked, the form control is updated with the value of the radio input.Steps to Reproduce
This code reproduction repository contains a stencil-library package and an
angular-workspace
package.The custom radio button component can be found in
packages/stencil-library/src/components/cust-radio/cust-radio.component.tsx
The value accessor config is defined in
packages/stencil-library/stencil.config.ts
using thevalueAccessorConfigs
property.The custom radio component is used in
packages/angular-workspace/projects/my-app/src/app/app.component.html
.The angular form group is defined in
packages/angular-workspace/projects/my-app/src/app/app.component.ts
Steps to reproduce:
Code Reproduction URL
https://github.com/adarean5/stencil-angular-radio-bug
Additional Information
As mentioned above, this behavior does not match the behaviour of using the Angular formControl with native HTML radio inputs (described here).
The Angular value accessor for radio inputs does not override the value of the native radio input. Instead, it sets the
checked
property based on whether the formContol value equals the radio input value. This is the implementation of thewriteValue
method in Angular'sRadioControlValueAccessor
, which handles reactive forms integration with native HTML radio inputs (source):This how the
writeValue
method of theValueAccessor
accessor class generated by Stencil looks like:The
writeValue
method of the Stencil-generatedValueAccessor
works differently than thewriteValue
method used by Angular to handle native radio inputs. It overrides the value of the input instead of toggling thechecked
attribute.The
RadioValueAccessor
generated by Stencil extends this value accessor and inherits thiswriteValue
method.The
RadioValueAccessor
generated by stencil should probably override thewriteValue
method from theValueAccessor
class with an implementation that is similar to the one in Angular.The text was updated successfully, but these errors were encountered: